Testing Overview

WPZylos plugins should be tested at multiple levels: unit tests, integration tests, and end-to-end tests.

Testing Strategy

graph TB
    subgraph Unit Tests
        A[Service Classes]
        B[Repositories]
        C[Utilities]
    end

    subgraph Integration Tests
        D[Database Operations]
        E[WordPress Hooks]
        F[Container Resolution]
    end

    subgraph E2E Tests
        G[Admin Pages]
        H[AJAX Endpoints]
        I[REST API]
    end

    A --> D
    D --> G

Test Directory Structure

tests/
+-- Unit/
|   +-- Services/
|   |   +-- ContactServiceTest.php
|   +-- Validation/
|   |   +-- ValidatorTest.php
|   +-- bootstrap.php
+-- Integration/
|   +-- Database/
|   |   +-- ConnectionTest.php
|   +-- Hooks/
|   |   +-- HookManagerTest.php
|   +-- bootstrap.php
+-- E2E/
    +-- Admin/
    |   +-- DashboardTest.php
    +-- bootstrap.php

PHPUnit Configuration

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
         bootstrap="tests/Unit/bootstrap.php"
         colors="true">
    <testsuites>
        <testsuite name="Unit">
            <directory>tests/Unit</directory>
        </testsuite>
        <testsuite name="Integration">
            <directory>tests/Integration</directory>
        </testsuite>
    </testsuites>

    <coverage>
        <include>
            <directory suffix=".php">src</directory>
        </include>
    </coverage>
</phpunit>

Running Tests

# All tests
vendor/bin/phpunit

# Unit tests only
vendor/bin/phpunit --testsuite=Unit

# Integration tests only
vendor/bin/phpunit --testsuite=Integration

# With coverage
vendor/bin/phpunit --coverage-html coverage/

Test Coverage Goals

LayerCoverage Target
Unit80%+
Integration60%+
E2ECritical paths

Testing Philosophy

  1. Unit tests verify individual classes work correctly in isolation
  2. Integration tests verify components work together with WordPress
  3. E2E tests verify user-facing features work end-to-end