跳转到内容
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

Thresholds, thread count and memory options live in infection.json5. CI enforces the same thresholds.

Make the CLI tools used by the shared quality workflow available on PATH: actionlint with its ShellCheck helper, codespell, EditorConfig Checker, markdownlint-cli2, Prettier and yamllint. Run all checks:

Terminal window
composer quality

Each tool also has its own script:

Terminal window
composer actionlint
composer codespell
composer editorconfig-checker
composer markdownlint
composer prettier
composer yamllint

The linter configuration lives in .github/linters, and the Prettier configuration in .prettierrc.json and .prettierignore. CI uses the same files.

Run static analysis.

Terminal window
composer static

Run the full test suite.

Terminal window
composer tests

Make zizmor and Gitleaks available on PATH. Audit the current workflow files with the same pedantic persona used by the shared security workflow:

Terminal window
composer zizmor

Scan Git history for secrets with the repository’s Gitleaks configuration:

Terminal window
composer gitleaks

Run both checks. Findings make the command fail; inspect them rather than disabling the checks.

Terminal window
composer security

Zizmor needs GitHub API access for its online audits. If the tool runs offline, report that limit separately. To request an offline audit explicitly:

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

The build workflow runs PHPUnit on PHP 8.3, 8.4, 8.5 and 8.6 on Ubuntu and Windows with the intl, mbstring and sodium extensions, once per supported Yii line: the phpunit job resolves Yii 22.0.x-dev and the phpunit-compatibility job resolves Yii 2.0.55 (the minimum supported release). Both jobs change the requirement with composer require yiisoft/yii2:<version> before running the suite. CI passes --ignore-platform-reqs to Composer only on PHP 8.6. The mutation test workflow still runs Infection with PHPStan on PHP 8.3.

To repeat either resolution locally, use separate disposable checkouts so their dependencies and lock files cannot affect each other:

Terminal window
composer require yiisoft/yii2:2.0.55 --with-all-dependencies
composer tests

Repeat in the other checkout with yiisoft/yii2:22.0.x-dev.

phpunit.xml.dist loads the package’s internal-function mocks. The suite uses the real bridge lifecycle and a deterministic Yii response. It verifies request limits, HEAD body suppression, emission before after-send, successive requests, failed emission/conversion, and finalization once when after-send throws.

These tests run under PHP CLI; they do not start FrankenPHP. To verify a deployment, use the quick start with the installed runtime and run the migration checks. Check native request reset, session isolation, upload reset, HEAD headers/body, partial-download bytes, and worker restarts. Record the runtime version and distinguish this evidence from mocked unit results.

Run the format tools over the guides and skill files after editing them:

Terminal window
composer markdownlint
composer prettier
composer editorconfig-checker

Back to documentation