CI / Tests (PHP 8.2) (pull_request) Successful in 53s
CI / No Debug Code (pull_request) Successful in 3s
CI / Coding Standards (pull_request) Successful in 2m54s
CI / PHPStan (pull_request) Successful in 3m0s
CI / Tests (PHP 8.1) (pull_request) Successful in 53s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m47s
CI / Build Plugin Zip (pull_request) Skipped
Most of this file described the repo as it was around v1.0: three domain packages, two database tables, twenty-one classes. There are now eleven packages, fifteen tables, and well over a hundred classes, so those sections were not just redundant with `ls` and Schema.php — they were teaching the wrong shape of the codebase. Same for the CI section, which had drifted past the build job. Cut the command list (composer.json has the scripts), the bootstrap description, the directory tree, the table list, the Key Classes table, and the CI job summary. Kept every rule the code can't explain on its own: package-by-domain, no $wpdb outside repositories, capability checks rather than role names, and the Schema.php version-bump gotcha. Moved the Brain\Monkey and Mockery gotchas to tests/CLAUDE.md, which loads only when working under tests/ instead of in every session. Co-Authored-By: Claude Opus 5 <[email protected]>
1.1 KiB
1.1 KiB
Writing tests
Tests use Brain\Monkey to stub WordPress functions without a full WP installation, and Mockery to mock $wpdb and other dependencies.
All test classes extend tests/Unit/TestCase.php, which handles Monkey\setUp() / Monkey\tearDown() and stubs all WP translation/escape functions automatically.
Brain\Monkey API notes:
Functions\when('fn')->alias(fn() => ...)— stub with a closure (NOTreturnUsing())Functions\when('fn')->justReturn($val)— stub returning a fixed valueFunctions\expect('fn')->once()->with(...)— assert call count and arguments- Use
Functions\when()(notFunctions\expect()) when you need argument-routing (e.g.get_rolereturning different values per argument) to avoid chaining ambiguity - Mockery matchers (e.g.
\Mockery::type()) inside plain PHP arrays do not work withwith()— use\Mockery::on(fn($arr) => ...)or\Mockery::any()instead - When mocking
$wpdb, set$mock->prefix = 'wp_'explicitly — it is a public property, not a method