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
| Layer | Coverage Target |
|---|---|
| Unit | 80%+ |
| Integration | 60%+ |
| E2E | Critical paths |
Testing Philosophy
- Unit tests verify individual classes work correctly in isolation
- Integration tests verify components work together with WordPress
- E2E tests verify user-facing features work end-to-end
Related
- Unit Testing — Writing unit tests
- Integration Testing — WordPress integration tests
- E2E Testing — Browser testing