Salta ai contenuti
PHP Ecosystem
Explore

Testing

Questi contenuti non sono ancora disponibili nella tua lingua.

This package provides a consistent set of Composer scripts for local validation. Install the development dependencies first:

Terminal window
composer install

Tool references:

The Testo configuration lives in testo.php and defines two suites:

  • Unit reads tests/ without tests/Composer, tests/Fixtures, tests/Provider and tests/Support. It holds the unit, command and functional tests, which run in the current process.
  • Composer reads tests/Composer. It runs a real Composer binary in subprocesses against temporary projects (see Real Composer tests).

Both suites fail a test on any PHP warning, notice or deprecation, and on a test without assertions (tests/Support/StrictTestPlugin.php). Filesystem failures are exercised against the real filesystem (a directory where a file is expected, a regular file as a parent directory, a missing source, chmod 0000), without function mocks; the chmod cases are skipped on Windows and when running as root.

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 -- --dry-run

Check coding standards without modifying files.

Terminal window
vendor/bin/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 with PHPStan static analysis enabled. Infection runs the Unit suite through testo/bridge-infection. This is the command CI runs.

Terminal window
composer mutation-static

Run mutation testing without static analysis.

Terminal window
composer mutation

Both runs reach the required score without ignored mutants. Thresholds, thread count and memory options live in infection.json5; the package requires a 100 % mutation score indicator (MSI) and covered MSI. The Composer suite is left out because its subprocesses install a snapshot of the working tree instead of running the mutated code.

The quality workflow runs Actionlint and uses the repository configurations for Codespell, EditorConfig Checker, Markdownlint-cli2, Prettier and Yamllint. The security workflow runs Zizmor with its pedantic persona and Gitleaks with the repository configuration. These checks are not exposed as Composer scripts in this package; run the individual tools directly with the checked-in configuration when reproducing a hosted check locally.

Report hosted workflow execution separately from local commands. Keep generated reports in ignored internal/ or runtime/ paths.

Run static analysis at level max with the strict checks from phpstan.neon. The Composer script removes the PHP memory limit.

Terminal window
composer static

Run both suites.

Terminal window
composer tests

Run only the Unit suite.

Terminal window
composer tests-unit

CI runs the suites on PHP 8.3, 8.4 and 8.5, on Ubuntu and Windows, and uploads the coverage to Codecov.

The Composer suite covers the plugin lifecycle and the provider integration that an in-process test cannot reproduce: composer install, update and create-project against a snapshot of this working tree and a provider fixture, offline. The harness uses the COMPOSER_BINARY environment variable when set; otherwise it looks for composer.phar and then composer on PATH. When none is available, every test of the suite is skipped.

Run only this suite:

Terminal window
composer tests -- --suite=Composer

Run it with a specific Composer PHAR:

Terminal window
COMPOSER_BINARY=/path/to/composer.phar composer tests -- --suite=Composer

Filter the tests by class or method name (the match is case-sensitive), and print a single JSON summary with the failed tests instead of the terminal report.

Terminal window
vendor/bin/testo --json --filter=ScaffolderTest

Collect coverage with PCOV or Xdebug enabled and write a Clover XML report.

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

Composer scripts forward additional arguments after --.

Run PHPStan with debug output.

Terminal window
composer static -- --debug