Testing
Este conteúdo não está disponível em sua língua ainda.
This package provides a consistent set of Composer scripts for local validation.
Tool references:
- Actionlint for GitHub Actions workflow linting.
- Codespell for spelling checks.
- Composer Require Checker for dependency definition checks.
- Easy Coding Standard (ECS) for coding standards.
- EditorConfig Checker for EditorConfig compliance.
- Gitleaks for secret scanning.
- Infection for mutation testing.
- Markdownlint-cli2 for Markdown linting.
- PHPStan for static analysis.
- Prettier for Markdown and YAML formatting checks.
- Rector for automated refactoring.
- Testo for unit tests and benchmarks.
- Yamllint for YAML linting.
- Zizmor for GitHub Actions security audits.
The Testo configuration lives in testo.php: the Unit suite reads tests/Unit and the Bench suite reads
tests/Bench. The Git compatibility cases live in tests/Fixtures/git-cases.json: each one stores two line lists and
the edit operations of git diff --no-index -U100000 run without user or system configuration
(GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_NOSYSTEM=1), since a configured diff.algorithm changes the result.
Automated refactoring (Rector)
Section titled “Automated refactoring (Rector)”Run Rector to apply automated code refactoring. This command modifies files.
composer rectorPreview the refactoring without modifying files.
composer rector-checkBenchmarks (Testo)
Section titled “Benchmarks (Testo)”Run the benchmarks that measure LineDiffer on its own and behind UnifiedDiffRenderer on the same generated input.
composer benchThe script runs testo --type=bench. Timings depend on the machine and the PHP version, so compare results from the
same run.
Coding standards (ECS)
Section titled “Coding standards (ECS)”Check coding standards without modifying files.
composer ecs-checkApply coding standard fixes. Review the changes before keeping them.
composer ecsDependency definition check
Section titled “Dependency definition check”Verify that runtime dependencies are correctly declared in composer.json.
composer check-dependenciesMutation testing (Infection)
Section titled “Mutation testing (Infection)”Run mutation testing with PHPStan static analysis enabled. Infection runs the Testo suites through
testo/bridge-infection. This is the command CI runs.
composer mutation-staticRun mutation testing without static analysis.
composer mutationBoth 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). CI enforces the same thresholds.
Repository quality checks
Section titled “Repository quality checks”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:
composer qualityEach tool also has its own script:
composer actionlintcomposer codespellcomposer editorconfig-checkercomposer markdownlintcomposer prettiercomposer yamllintThe linter configuration lives in .github/linters, and the Prettier configuration in .prettierrc.json and
.prettierignore. CI uses the same files.
Static analysis (PHPStan)
Section titled “Static analysis (PHPStan)”Run static analysis at level max.
composer staticUnit tests (Testo)
Section titled “Unit tests (Testo)”Run the test suites without the benchmarks.
composer testsThe script runs testo --type=!bench. CI runs the same command on PHP 8.3, 8.4 and 8.5, on Ubuntu and Windows, and
uploads the coverage to Codecov.
Running one test
Section titled “Running one test”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.
vendor/bin/testo --json --filter=LineDifferTestvendor/bin/testo --json --filter=matchesGitEditOperationsCode coverage
Section titled “Code coverage”Collect coverage with PCOV or Xdebug enabled and write a Clover XML report.
vendor/bin/testo --coverage-clover=runtime/clover.xmlWorkflow security checks
Section titled “Workflow security checks”Make zizmor and Gitleaks available on PATH. Audit the current workflow files with the same pedantic persona used by
the shared security workflow:
composer zizmorScan Git history for secrets with the repository’s Gitleaks configuration:
composer gitleaksRun both checks. Findings make the command fail; inspect them rather than disabling the checks.
composer securityZizmor needs GitHub API access for its online audits. If the tool runs offline, report that limit separately. To request an offline audit explicitly:
composer zizmor -- --offlineReport hosted CI execution and its PHP/OS matrix separately from these local commands. Keep generated reports in ignored
runtime/ or internal/.
Passing extra arguments
Section titled “Passing extra arguments”Composer scripts support forwarding additional arguments using --.
Run the Testo suites with a Clover coverage report.
composer tests -- --coverage-clover=runtime/clover.xmlRun only the tests of one suite.
composer tests -- --suite=UnitRun PHPStan with a different memory limit.
composer static -- --memory-limit=512M