Skip to content
PHP Ecosystem
Explore

Testing

This package provides a consistent set of Composer scripts for local validation.

Tool references:

Run Rector to apply automated code refactoring. This command modifies files.

Terminal window
composer rector

Preview the refactoring without modifying files.

Terminal window
composer rector-check

Check coding standards without modifying files.

Terminal window
composer ecs-check

Apply coding standard fixes. Review the changes before keeping them.

Terminal window
composer ecs

Verify that runtime dependencies are correctly declared in composer.json.

Terminal window
composer check-dependencies

Run mutation testing.

Terminal window
composer mutation

Run mutation testing with PHPStan static analysis enabled.

Terminal window
composer mutation-static

Infection runs the sqlite group, so it needs no database service. CI enforces the thresholds in infection.json5.

CI runs actionlint, codespell, EditorConfig Checker, markdownlint-cli2, Prettier and yamllint through the shared yii2-framework/actions quality workflow. The repository’s formatting rules stay in .editorconfig.

Make actionlint and ShellCheck available on PATH to lint workflows locally.

Terminal window
composer actionlint

Run static analysis.

Terminal window
composer static

The test suite uses SQLite in memory. Install dependencies for one Yii release at a time and repeat with the other version to check compatibility.

Terminal window
composer update --with yiisoft/yii2:2.0.55
composer tests

Use 22.0.x-dev in place of 2.0.55 for the Yii 22 check. To generate a Clover report with PCOV or Xdebug, run:

Terminal window
composer tests -- --coverage-clover runtime/coverage.xml

SQLite runs with composer tests and does not need a database service. The other drivers have their own workflows. Composer requires only pdo_sqlite; each other group also needs its PHP PDO driver: pdo_mysql for mysql, pdo_pgsql for pgsql, pdo_sqlsrv for mssql and pdo_oci for oci. To run a group locally, start that driver’s disposable database and run the matching command:

Terminal window
vendor/bin/phpunit --group mysql
vendor/bin/phpunit --group pgsql
vendor/bin/phpunit --group mssql
vendor/bin/phpunit --group oci

Connection defaults match each workflow’s test service. To override a connection, set SOFT_DELETE_TEST_<DRIVER>_DSN, SOFT_DELETE_TEST_<DRIVER>_USERNAME, or SOFT_DELETE_TEST_<DRIVER>_PASSWORD, using MYSQL, PGSQL, MSSQL, or ORACLE as the driver name. Use an empty database dedicated to tests.

CI runs zizmor and Gitleaks through the shared security workflow. Gitleaks uses its default rules. The Gitleaks scan requires GITLEAKS_LICENSE in the workflow.

Make zizmor available on PATH to audit the workflows locally with the same pedantic persona.

Terminal window
composer zizmor

Zizmor needs GitHub API access for its online audits. Use the offline flag to run without API access.

Terminal window
composer zizmor -- --offline

Report hosted CI execution and its PHP/OS matrix separately from these local commands. Keep generated reports in ignored internal/.

Composer scripts support forwarding additional arguments using --.

Run PHPUnit with code coverage report generation.

Terminal window
composer tests -- --coverage-html internal/coverage

Run PHPStan with a different memory limit.

Terminal window
composer static -- --memory-limit=512M

Back to documentation