Verify PHPSpec Usage:
Ensure phpspec/phpspec is installed in your project (composer show phpspec/phpspec). The adapter auto-detects it via infection/extension-installer.
Install the Adapter:
composer require --dev infection/phpspec-adapter
No manual configuration is required—the adapter registers automatically via Infection’s auto-discovery.
Run Infection:
vendor/bin/infection --test-framework=phpspec
Omit --test-framework if PHPSpec is your only test framework; Infection auto-detects it.
Check Output:
Review the mutation report (e.g., infection.log) for:
Scenario: Your team relies on PHPSpec for BDD-style testing but wants to ensure tests aren’t brittle or missing edge cases. Workflow:
vendor/bin/infection --test-framework=phpspec --threads=4 --min-msi=90
--threads=4: Parallelize mutations (critical for large codebases).--min-msi=90: Require 90% Mutation Score Improvement (only report projects meeting this threshold).--format=pretty to debug why a test missed a mutation.Expected Outcome:
it_should_throw_when for invalid inputs).UserService.php").Adapter Auto-Detection:
vendor/infection/extension-installer logs if Infection fails to detect PHPSpec.phpspec/phpspec is in composer.json under require-dev.PHPSpec Configuration:
phpspec.yml (no overrides needed).extensions: in phpspec.yml are compatible (e.g., avoid custom extensions that break Infection’s interceptor).Infection Configuration:
infection.json5.dist for PHPSpec-specific needs:
{
"test_framework": "phpspec",
"threads": 2,
"min_msi": 80,
"include_paths": ["src", "tests/spec"],
"exclude_paths": ["tests/spec/Unit/*"] // Skip unit specs if using BDD-only
}
Step-by-Step:
Add to CI Pipeline (GitHub Actions example):
- name: Run Infection with PHPSpec
run: vendor/bin/infection --test-framework=phpspec --threads=2 --min-msi=85
push to main or pull_request events.actions/cache for vendor/ to speed up parallel runs.Parallelization Strategy:
vendor/bin/infection --test-framework=phpspec --threads=4 --include-paths="src/Service,src/Repository"
--memory-limit=1G) to adjust --threads.Reporting:
vendor/bin/infection --test-framework=phpspec --report=html --output=infection-report
- uses: actions/upload-artifact@v3
with:
name: infection-report
path: infection-report/
phpspec/phpspec with Laravel’s pestphp/pest (which supports PHPSpec-like syntax), configure Infection to target:
vendor/bin/infection --test-framework=phpspec --include-paths="tests/Feature,tests/Unit"
app/Providers/ and app/Console/:
// infection.json5.dist
{
"include_paths": ["app/Providers/*ServiceProvider.php"],
"min_msi": 95 // Stricter for core logic
}
phpspec/extension-code-coverage) may conflict with Infection’s interceptor.{
"exclude_paths": ["vendor/phpspec/*"]
}
--no-intercept for problematic extensions (limits mutation coverage).vendor/bin/infection --test-framework=phpspec --include-paths="tests/spec"
vendor/bin/infection --test-framework=phpunit --include-paths="tests/Unit"
infection.json5.dist to focus on high-risk files:
{
"include_paths": [
"src/UseCases/**/*",
"src/Repositories/**/*"
],
"exclude_paths": [
"src/Models/*", // Skip if already covered by Pest/PHPUnit
"tests/spec/Integration/*" // Run separately
]
}
--mutate-only to target specific files:
vendor/bin/infection --test-framework=phpspec --mutate-only=src/UserService.php
UserServiceSpec.php to add missing it_should cases.- name: Check Infection MSI
run: |
MSI=$(grep -oP 'Mutation Score Improvement: \K\d+' infection.log)
if [ "$MSI" -lt 80 ]; then
echo "MSI $MSI below threshold (80)."
exit 1
fi
rules to catch static issues, then Infection to validate dynamic behavior.vendor/bin/phpstan analyse --level=max
vendor/bin/infection --test-framework=phpspec --min-msi=90
NoCodeCoverageException.phpunit.xml config).phpspec.yml includes:
extensions:
PhpSpec\Extension\CodeCoverageExtension:
format: [clover]
output: [coverage/clover.xml]
Then configure Infection to use the coverage file:
// infection.json5.dist
{
"coverage": "coverage/clover.xml"
}
vendor/bin/infection --test-framework=phpspec --no-intercept-extensions
Allowed memory exhausted onHow can I help you explore Laravel packages today?