fair-plugin/tests/unit
Chuck Adams febfe93a87
Revert null-transient normalization, split multi-class test files
- Revert the null-to-'' normalization in validate_package_alias()
  that caused cache falsey-value collisions on single-site
- Add test_should_cache_null_result (incomplete) documenting the
  null-transient bug and sentinel-based fix
- Split all test files to one class per file (10 files → 31 files)
- Rename test files to match their single class name

Signed-off-by: Chuck Adams <chaz@chaz.works>
2026-06-09 22:45:28 -06:00
..
tests Revert null-transient normalization, split multi-class test files 2026-06-09 22:45:28 -06:00
bootstrap.php Phase 1: migrate test infrastructure to tests/unit/ 2026-06-09 10:59:50 -06:00
multisite.xml Phase 13: coverage baseline + Infection mutation testing 2026-06-09 14:46:33 -06:00
phpunit.xml Phase 13: coverage baseline + Infection mutation testing 2026-06-09 14:46:33 -06:00
README.md Phase 1: migrate test infrastructure to tests/unit/ 2026-06-09 10:59:50 -06:00

Instructions

Setting up the dev environment

Option 1: wp-env

  1. Copy wp-tests-config-sample.php to wp-tests-config.php.
  2. Ensure Docker is installed and running.
  3. Run npm i
  4. Run npm run env start
  5. 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.php to wp-tests-config.php.
  • Ensure that DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST in wp-tests-config.php match your setup.
  • Run ./bin/install-wp-tests.sh with 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.