phpspec/phpspec.phpspec/phpspec is already in composer.json, Infection’s extension-installer will auto-detect and install infection/phpspec-adapter. For manual setups:
composer require --dev infection/phpspec-adapter
phpspec.yml or phpspec.neon.register() method if needed (though auto-discovery suffices).| Risk Area | Mitigation |
|---|---|
| PHPSpec Version Mismatch | Adapter explicitly checks PHPSpec version compatibility. If unsupported, throws a dedicated VersionNotSupportedException (added in v0.3.0). |
| Test Flakiness | Infection requires at least one passing test to validate mutations (enforced in v0.3.0). Flaky tests will bail out early, reducing false positives. |
| Performance Overhead | Mitigated by: |
--parallel flag.--min-msi to skip trivial mutations (e.g., dead code). |
| Laravel-Specific Quirks | PHPSpec’s autoloading may conflict with Laravel’s PSR-4. Adapter injects a custom autoloader template to handle this (fixed in v0.3.0 PR #97). Test in a staging environment before full adoption. |
| Maintenance Burden | Low-risk:composer update when Infection/PHPSpec major versions change.vendor/bin/infection).infection/extension-installer if PHPSpec is present.--test-framework flag to isolate PHPSpec mutations.| Phase | Action Items | Dependencies |
|---|---|---|
| Prep | 1. Audit composer.json for phpspec/phpspec. |
PHPSpec v6.0+ |
| 2. Ensure PHP 8.3+ and Laravel 10.x+ (or custom PHP 8.3 setup). | Laravel/PHP version | |
3. Add infection/infection to devDependencies. |
Infection v0.32.0+ | |
| Installation | 4. Run composer require --dev infection/phpspec-adapter. |
Composer |
5. Verify auto-discovery via vendor/bin/infection --list-adapters. |
Infection | |
| Configuration | 6. Update infection.json5 (if needed): |
infection.json5 |
| ```json5 | ||
| { | ||
| "test_framework": "phpspec", | ||
| "min_msi": 0.8, // Only report mutations killing >=80% of tests | ||
| "threads": 4, // Parallelize for CI | ||
| "include_paths": ["tests/unit", "tests/features"] | ||
| } | ||
| ``` | ||
| Validation | 7. Run locally: vendor/bin/infection --only-covered. |
Local PHP environment |
8. Check CI: Add to .github/workflows/php.yml: |
GitHub Actions | |
| ```yaml | ||
| - name: Mutation Testing | ||
| run: vendor/bin/infection --parallel --min-msi=0.9 | ||
| ``` | ||
| Optimization | 9. Tune thresholds (--min-msi) based on false positives. |
Test suite stability |
10. Exclude flaky specs with infection.json5 "exclude_paths". |
PHPSpec test stability |
null extensions gracefully (PR #65).// app/Console/Commands/MutationTest.php
public function handle() {
Artisan::call('infection', ['--test-framework' => 'phpspec']);
}
How can I help you explore Laravel packages today?