infection/include-interceptor
PHP stream wrapper that intercepts the file:// protocol to override the content of any included or autoloaded file at runtime. Register a mapping from original file to replacement, enable the interceptor, and includes/file_get_contents load the replacement instead.
Architecture fit:
The infection/include-interceptor package leverages PHP's stream wrapper system to intercept and replace file inclusions at runtime. In a Laravel context, this is highly niche but strategically valuable for:
--parallel). However, it remains misaligned with Laravel’s production workflows, where include/require usage is minimal and Composer autoloading dominates.Integration feasibility:
phpunit.xml or tests/bootstrap.php).vendor/ or bootstrap/ paths.Technical risk:
| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| Autoloader conflicts | Medium | Register wrapper in test bootstrap only. |
| File locking deadlocks | Low (fixed) | 0.2.5’s lock constant fix reduces risk. |
| PHP version skew | Medium | Pin to PHP 8.0+ in composer.json. |
| Stream wrapper collisions | Low | Avoid in production; test-only scope. |
Key questions:
filesystem disk drivers (e.g., local, s3) or cached compiled views (bootstrap/cache)?Illuminate\Filesystem\Filesystem or Illuminate\Foundation\Application file operations?Artisan::call(), Http::fake()) that may use include internally?Stack fit:
include/require usage in core workflows).Filesystem or Laravel’s Illuminate/Filesystem.Migration path:
composer require --dev infection/include-interceptor:0.2.5
--dev to scope to test environments.phpunit.xml bootstrap:
<php>
<includePath>./vendor/infection/include-interceptor/bootstrap.php</includePath>
</php>
tests/bootstrap.php:
if (app()->environment('testing')) {
IncludeInterceptor::enable();
}
include/require calls to verify interception:
use Infection\IncludeInterceptor\Interceptor;
public function testIncludeInterception() {
$interceptor = new Interceptor();
$interceptor->intercept(
__DIR__.'/stubs/original.php',
__DIR__.'/stubs/replacement.php'
);
$interceptor->enable();
include __DIR__.'/stubs/original.php'; // Loads replacement.php
$this->assertTrue(true); // Verify no errors.
}
Compatibility:
Sequencing:
vendor/autoload.php).phpunit.xml or bootstrap.php).app()->environment('testing') to prevent production impact.IncludeInterceptor::disable();
Maintenance:
README section for Laravel test setup (e.g., bootstrap timing, conflict examples).phpunit.xml snippet for quick adoption.Support:
Scaling:
--parallel.include (negligible for most suites).php -d memory_limit=512M).Failure modes:
| Scenario | Impact | Detection | Mitigation |
|---|---|---|---|
| Premature registration | Autoloader corruption | Silent failures in tests | Register in phpunit.xml only. |
| File locking deadlocks | Test hangs/corruption | CI timeouts or flaky tests | Use --parallel cautiously; pin PHP version. |
| Infection/PHPUnit version skew | Undefined behavior | Mutation test failures | Pin versions in composer.json. |
| Stream wrapper collisions | Unpredictable file loads | Tests load wrong files | Disable Xdebug’s file cache. |
Ramp-up:
composer require --dev infection/include-interceptor
# Add to phpunit.xml
vendor/bin/phpunit --testdoxhtml
README section with:
How can I help you explore Laravel packages today?