-
Notifications
You must be signed in to change notification settings - Fork 0
Testing and Quality
The repository uses three complementary layers:
- Unit tests (
tests/Unit) with Brain\Monkey and Mockery - Integration tests (
tests/Integration) with WordPress Test Suite - E2E tests (
tests/e2e) with Playwright +@wordpress/env
Current test file counts:
- Unit test files:
31 - Integration test files:
24 - PHP test files total:
55 - E2E spec files:
5
Source files:
-
src/PHP files:31
Current test counts:
- Unit tests:
574(1336 assertions) - Integration tests:
322(655 single-site / 684 multisite assertions) - E2E scenarios:
46(138 local runs across 3 viewports; desktop-only in CI)
Configuration:
phpunit.xml.dist- Test bootstrap:
tests/bootstrap.php
Suites:
unitintegration
Bootstrap behavior:
- Always defines
ABSPATHfor source guards - Loads WP Test Suite only when integration suite is detected
- Loads plugin through
muplugins_loadedin integration mode - Supports
WP_TESTS_MULTISITEenv var for multisite mode
Focus:
- Isolated business logic
- Hook and WP function interaction contracts
- Architectural constraints (no singleton/static/final patterns)
Command:
composer test:unit
Focus:
- Real WordPress APIs (options, transients, cron, admin pages)
- DB-level and hook-level behavior
- End-to-end flow inside WP runtime (excluding browser)
Setup:
composer install-wp-tests
Command:
composer test:integration
The bootstrap supports the WP_TESTS_MULTISITE environment variable:
// tests/bootstrap.php
if ( getenv( 'WP_TESTS_MULTISITE' ) ) {
define( 'WP_TESTS_MULTISITE', true );
}When active, the WordPress Test Suite loads WordPress as a multisite network.
Commands:
| Command | Description |
|---|---|
composer test:integration:multisite |
Integration tests in multisite mode |
composer test:coverage:multisite |
Multisite integration coverage (clover XML) |
composer test:coverage |
3 suites: unit + integration + multisite |
Dedicated tests in tests/Integration/Core/UninstallerTest.php (3 multisite tests):
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Requires multisite.' );
}Coverage: the is_multisite() branch in Uninstaller::uninstall() is 100% covered only by combining single-site (the else branch) + multisite (the if branch). The separate clover XML reports (clover-integration.xml + clover-multisite.xml) are automatically merged by Codecov.
For more details see Multisite Support.
Tech stack:
@playwright/test-
@wordpress/env(Docker WordPress)
Viewport projects:
- Local: desktop, tablet, mobile
- CI: desktop only
Key config:
workers: 1timeout: 30s local / 60s CIretries: 1 local / 2 CI
Commands:
npm run env:startbash bin/e2e-setup.shnpm run test:e2enpm run env:stop
Every test class MUST include two pattern enforcement tests:
/**
* Verifies that the class is NOT final
*/
public function test_class_is_not_final() {
$reflection = new \ReflectionClass( MyClass::class );
$this->assertFalse( $reflection->isFinal(), 'Class should NOT be final' );
}
/**
* Verifies that NO static methods exist (excluding magic methods)
*/
public function test_no_static_methods() {
$reflection = new \ReflectionClass( MyClass::class );
$methods = $reflection->getMethods( \ReflectionMethod::IS_STATIC );
$static_methods = array_filter( $methods, function( $method ) {
return strpos( $method->getName(), '__' ) !== 0;
} );
$this->assertEmpty( $static_methods, 'Class should have NO static methods' );
}Notes:
- The
strpos($name, '__') !== 0filter excludes magic methods (__callStatic, etc.) from the check - This requirement is non-negotiable and verified in code review
- Pattern enforcement tests are present in all 55 PHP test classes
PHPCS:
- Config:
.phpcs.xml.dist - Standards: WordPress + WordPress-Extra + WordPress-Docs + PHPCompatibilityWP
- Command:
composer phpcs
PHPStan:
- Level: 6
- Config:
phpstan.neon - WordPress extension:
szepeviktor/phpstan-wordpress - Command:
composer analyse
Coverage commands:
-
composer test:coverage— runs 3 suites: unit + integration + multisite composer test:coverage:unitcomposer test:coverage:integrationcomposer test:coverage:multisite
Clover XML output:
coverage/clover-unit.xmlcoverage/clover-integration.xmlcoverage/clover-multisite.xml
Codecov configuration:
codecov.yml- Separate flags:
unit,integration - Single-site and multisite combined by Codecov with
carryforward: true - Project target: 95%
Script: bin/test-matrix.sh
Capabilities:
- PHP matrix
7.4to8.5 - Runs PHPCS + PHPStan + PHPUnit
- Optional E2E execution
- Supports sequential or parallel modes
Useful modes:
composer test:matrixbin/test-matrix.sh --parallelbin/test-matrix.sh --php 8.3bin/test-matrix.sh --tests-onlybin/test-matrix.sh --e2e-only