Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Include Interceptor Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

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:

  • Mutation testing (e.g., Infection integration).
  • Custom test instrumentation (e.g., tracking included files for coverage gaps).
  • Debugging autoloading issues in test environments. The 0.2.5 lock constant fix mitigates a critical race condition risk, making it more reliable for parallel test execution (e.g., Pest or PHPUnit --parallel). However, it remains misaligned with Laravel’s production workflows, where include/require usage is minimal and Composer autoloading dominates.

Integration feasibility:

  • High for test environments: The package’s design (stream wrapper registration) is compatible with Laravel’s test bootstrapping (e.g., phpunit.xml or tests/bootstrap.php).
  • Moderate for custom tools: Requires explicit registration after Composer autoloading but before test execution to avoid autoloader conflicts. The lock constant fix reduces but does not eliminate the risk of file corruption in high-concurrency scenarios.
  • Low for production: No impact on Laravel’s core 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:

  1. Laravel-specific conflicts:
    • Does the stream wrapper interfere with Laravel’s filesystem disk drivers (e.g., local, s3) or cached compiled views (bootstrap/cache)?
    • Are there edge cases with Laravel’s Illuminate\Filesystem\Filesystem or Illuminate\Foundation\Application file operations?
  2. Test tooling compatibility:
    • How does the package interact with Laravel’s built-in test helpers (e.g., Artisan::call(), Http::fake()) that may use include internally?
    • Does it conflict with Pest, Laravel Zero, or custom test runners?
  3. Performance:
    • What is the measurable overhead of the stream wrapper in a Laravel test suite with 100+ test files?
    • Does the lock constant fix introduce latency in CI environments with high test parallelism?
  4. Maintenance:
    • What is the long-term viability of the package? The last major release was in 2021, but 0.2.5 (2026) suggests responsive maintenance.
    • Are there Laravel-specific forks or alternatives (e.g., Xdebug, custom stream wrappers)?

Integration Approach

Stack fit:

  • Primary use case: Test instrumentation (mutation testing, coverage analysis, debugging).
  • Secondary use case: Custom CLI tools (e.g., pre-deployment checks for unauthorized file inclusions).
  • Non-use case: Production Laravel applications (no include/require usage in core workflows).
  • Compatibility:
    • Laravel 8+: No known conflicts with Symfony’s Filesystem or Laravel’s Illuminate/Filesystem.
    • PHP 8.0+: Aligns with Laravel’s supported PHP versions; lock constant fix is compatible.
    • Composer: Zero conflicts with autoloading; operates at the stream wrapper level.

Migration path:

  1. Installation:
    composer require --dev infection/include-interceptor:0.2.5
    
    • Use --dev to scope to test environments.
  2. Registration:
    • Option 1: Add to phpunit.xml bootstrap:
      <php>
          <includePath>./vendor/infection/include-interceptor/bootstrap.php</includePath>
      </php>
      
    • Option 2: Register in tests/bootstrap.php:
      if (app()->environment('testing')) {
          IncludeInterceptor::enable();
      }
      
  3. Validation:
    • Create a test file with explicit 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:

  • Laravel-specific tools:
    • Infection: Native support; use as a backend for mutation testing.
    • Pest/PHPUnit: Safe for parallel execution (lock constant fix mitigates deadlocks).
    • Laravel Forge/Envoyer: No impact; package is test-scoped.
  • Third-party packages:
    • Xdebug: May conflict if both stream wrappers are active; disable Xdebug’s file cache during tests.
    • Static analyzers (PHPStan, Psalm): No known conflicts; operates at runtime.

Sequencing:

  1. Critical order:
    • Register after Composer autoloading (vendor/autoload.php).
    • Enable before test execution (e.g., in phpunit.xml or bootstrap.php).
  2. Avoid global scope:
    • Wrap in app()->environment('testing') to prevent production impact.
  3. Cleanup:
    • Disable after tests (optional):
      IncludeInterceptor::disable();
      

Operational Impact

Maintenance:

  • Low effort: Update via Composer; no Laravel-specific configuration.
  • Documentation needs:
    • Add a README section for Laravel test setup (e.g., bootstrap timing, conflict examples).
    • Example phpunit.xml snippet for quick adoption.
  • Deprecation risk:
    • Monitor for Laravel-specific forks or alternatives (e.g., custom stream wrappers).
    • If the package stagnates, consider forking for Laravel-specific fixes.

Support:

  • Test environments:
    • Primary support scope; troubleshoot autoloader conflicts or file locking issues.
    • Provide templates for Infection/Pest integration.
  • Production:
    • No support needed; package is opt-in for tests only.
  • CI/CD:
    • Add to test matrix; validate in parallel execution (e.g., GitHub Actions, GitLab CI).

Scaling:

  • Parallel tests:
    • 0.2.5’s lock constant fix reduces deadlocks in Pest/PHPUnit --parallel.
    • Benchmark overhead: ~1–5ms per include (negligible for most suites).
  • Large codebases:
    • Memory usage scales with intercepted files; monitor for leaks in long-running tests.
  • Resource constraints:
    • Disable in CI if tests exceed memory limits (e.g., 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:

  • For TPMs:
    • Adoption criteria: Only consider if building mutation testing, custom analyzers, or debugging tools.
    • Alternatives: Evaluate Xdebug or custom stream wrappers if the package lacks maintenance.
  • For Developers:
    • Setup time: <15 minutes (install + bootstrap config).
    • Training: Focus on test-only usage; avoid production.
    • Example workflow:
      composer require --dev infection/include-interceptor
      # Add to phpunit.xml
      vendor/bin/phpunit --testdoxhtml
      
  • Onboarding docs:
    • Include a Laravel-specific README section with:
      • Bootstrap configuration examples.
      • Common pitfalls (e.g., autoloader conflicts).
      • Performance benchmarks for large suites.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
calliostro/spotify-bundle
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle