tests/php/readme.md documents running the tests from inside the Jetpack monorepo only:
- Run
jetpack install plugins/crm
- Go to the crm plugins directory
projects/plugins/crm
- Run
composer run-script phpunit
None of that applies to a standalone clone of this repo, which is how it ships and what make up sets up. make test runs composer phpunit, which needs a WordPress test library the readme never mentions, so the first thing you hit is a fatal about a missing wp-settings.php.
The test library is already there. make up starts wp-env, and its tests container ships the WordPress test suite at /wordpress-phpunit with the plugin mounted, so the whole suite runs with one command:
docker exec -w /var/www/html/wp-content/plugins/jetpack-crm zero-bs-crm-tests-cli-1 \
sh -c 'WORDPRESS_DEVELOP_DIR=/wordpress-phpunit php vendor/bin/phpunit -c phpunit.12.xml.dist'
Worth documenting, along with a few things that took a while to work out:
composer phpunit does not work inside the container. It calls vendor/bin/phpunit-select-config, which uses pcntl_exec, and that isn't available there. Call vendor/bin/phpunit directly with the config matching your PHPUnit version.
phpunit.12.xml.dist is a symlink to phpunit.11.xml.dist. If you are adding a <testsuite> and dutifully edit "both", you write the same file twice and end up with a duplicated block.
WP_Ajax_UnitTestCase puts its tests in the ajax group, which the WordPress bootstrap excludes unless you pass --group ajax. Tests written on it are silently skipped, so a suite that never runs still reports green.
wp_send_json() only sets a status code when headers_sent() is false, which it never is under PHPUnit. Asserting on a handler's response status passes regardless of what the handler decided, so those assertions are worth nothing. Assert on the body instead.
make lint has the same gap. composer cs shells out to phpcs-changed, which isn't in require-dev and isn't vendored, and there's no vendor/bin/phpcs either, so linting can't be run from a standalone clone at all. Either add the dependency or say plainly in the readme that linting is monorepo-only.
Happy to send a PR if the direction looks right.
tests/php/readme.mddocuments running the tests from inside the Jetpack monorepo only:None of that applies to a standalone clone of this repo, which is how it ships and what
make upsets up.make testrunscomposer phpunit, which needs a WordPress test library the readme never mentions, so the first thing you hit is a fatal about a missingwp-settings.php.The test library is already there.
make upstarts wp-env, and its tests container ships the WordPress test suite at/wordpress-phpunitwith the plugin mounted, so the whole suite runs with one command:Worth documenting, along with a few things that took a while to work out:
composer phpunitdoes not work inside the container. It callsvendor/bin/phpunit-select-config, which usespcntl_exec, and that isn't available there. Callvendor/bin/phpunitdirectly with the config matching your PHPUnit version.phpunit.12.xml.distis a symlink tophpunit.11.xml.dist. If you are adding a<testsuite>and dutifully edit "both", you write the same file twice and end up with a duplicated block.WP_Ajax_UnitTestCaseputs its tests in theajaxgroup, which the WordPress bootstrap excludes unless you pass--group ajax. Tests written on it are silently skipped, so a suite that never runs still reports green.wp_send_json()only sets a status code whenheaders_sent()is false, which it never is under PHPUnit. Asserting on a handler's response status passes regardless of what the handler decided, so those assertions are worth nothing. Assert on the body instead.make linthas the same gap.composer csshells out tophpcs-changed, which isn't inrequire-devand isn't vendored, and there's novendor/bin/phpcseither, so linting can't be run from a standalone clone at all. Either add the dependency or say plainly in the readme that linting is monorepo-only.Happy to send a PR if the direction looks right.