Rename tests/phpunit/ → tests/unit/, phpunit.xml.dist → tests/unit/phpunit.xml. Adjust all paths in phpunit.xml and multisite.xml for new location. Update composer.json scripts: test → test:unit, test:multisite → test:unit:multisite. Update coverage:* paths and package.json npm scripts. Bump .wp-env.json PHP version 7.4 → 8.0 (hard floor per AGENTS.md). All 19 existing tests pass (5 test classes, 30 assertions). Known issue: composer.lock has PHP 8.2-bound dev deps; tests-cli needs --ignore-platform-reqs on PHP 8.0. Signed-off-by: Chuck Adams <chaz@chaz.works>
1.9 KiB
Instructions
Setting up the dev environment
Option 1: wp-env
- Copy
wp-tests-config-sample.phptowp-tests-config.php. - Ensure Docker is installed and running.
- Run
npm i - Run
npm run env start - Run
npm run test:php:install-deps
Option 2: Local web server and MySQL database:
- Run
composer install - Create a new database using
mysql -u<username> -p->CREATE DATABASE <database_name>;->exit;- Note: Don't use an existing database - the database is reset before every test run by default.
- Copy
wp-tests-config-sample.phptowp-tests-config.php. - Ensure that
DB_NAME,DB_USER,DB_PASSWORD, andDB_HOSTinwp-tests-config.phpmatch your setup. - Run
./bin/install-wp-tests.shwith the appropriate credentials.
Running PHPUnit tests
Single Site
npm run test:php
If you're not using wp-env, you can just run composer run test:unit.
Multisite
npm run test:php:multisite
If you're not using wp-env, you can just run composer run test:unit:multisite.
Running PHPUnit tests with line coverage
First, start the environment with xDebug:
npm run env start -- --xdebug=coverage
If you're not using wp-env, make sure the xDebug PHP module is installed and enabled.
Single Site
npm run coverage:php:single
If you're not using wp-env, you can just run composer run coverage:single.
A coverage report will be available at /tests/unit/coverage/html/single-site.
Multisite
npm run coverage:php:multisite
If you're not using wp-env, you can just run composer run coverage:multisite.
A coverage report will be available at /tests/unit/coverage/html/multisite.
Single Site and Multisite
npm run coverage:php:full
If you're not using wp-env, you can just run composer run coverage:full.
A merged coverage report will be available at /tests/unit/coverage/html/full.