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

React Phpunit Run Tests In Fiber Laravel Package

wyrihaximus/react-phpunit-run-tests-in-fiber

PHPUnit trait to run each test inside a PHP Fiber, making it easy to use ReactPHP async/await in tests. Includes optional per-test or per-class timeout attributes to fail slow tests (without stopping the running fiber).

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture fit: This package is a poor fit for standard Laravel applications due to its reliance on ReactPHP fibers, which are incompatible with Laravel’s synchronous testing framework and async tools (e.g., queues, Guzzle HTTP clients). It is only viable for projects explicitly using ReactPHP’s event loop (e.g., custom async services, non-blocking I/O). For Laravel, this would require a custom integration layer to bridge fibers with Laravel’s test lifecycle (e.g., database transactions, service providers).

Integration feasibility: Low for most Laravel use cases. The package assumes a ReactPHP-centric environment, while Laravel’s default stack (Symfony components, queues, HTTP clients) operates outside fibers. Integration would require:

  • Event loop isolation: Preventing fiber conflicts with Laravel’s async workers (e.g., queue listeners).
  • Test lifecycle compatibility: Ensuring fibers don’t interfere with Laravel’s test bootstrapping (e.g., TestCase::setUp()).
  • Dependency conflicts: ReactPHP’s react/async may clash with Laravel’s native async tools (e.g., spatie/async or laravel-horizon).

Technical risk:

  • High: Minimal adoption (0 stars, 0 dependents) and no active maintenance history beyond recent updates. Risk of:
    • Silent failures: Fibers may leak or conflict with Laravel’s global state (e.g., singleton services).
    • Test flakiness: Timeouts or race conditions in fiber contexts could produce inconsistent results.
    • Debugging complexity: Stack traces for fiber-related errors are harder to interpret in Laravel’s synchronous stack.
  • Dependency lock-in: Requires PHP 8.4+ and PHPUnit 12+, which may not align with Laravel’s supported versions.

Key questions:

  1. Does the project use ReactPHP fibers for core async logic? If not, this package is irrelevant.
  2. Can fibers coexist with Laravel’s async tools (queues, HTTP clients)? Likely not without significant refactoring.
  3. Is the team experienced with ReactPHP fibers? Lack of expertise increases risk of misconfiguration.
  4. What’s the failure mode if fibers conflict with Laravel’s test lifecycle? (e.g., database transactions, service binding).
  5. Are there alternatives? (e.g., Laravel’s built-in async testing for queues, or custom test doubles for async services).

Integration Approach

Stack fit:

  • Target use case: Projects using ReactPHP for async services (e.g., WebSocket handlers, event processors) where await() is required in tests.
  • Laravel compatibility: Limited. The package is incompatible with:
    • Laravel’s synchronous test runner (PHPUnit’s default).
    • Async tools like queues, Guzzle HTTP clients, or spatie/async.
    • Database transactions (fibers may bypass Laravel’s transaction middleware).
  • Workaround: Isolate fiber-based tests in a separate test suite with a custom PHPUnit bootstrap that initializes the ReactPHP event loop.

Migration path:

  1. Assess feasibility: Confirm the project exclusively uses ReactPHP fibers (no Laravel async tools).
  2. Isolate scope:
    • Add the package to composer.json under require-dev.
    • Create a dedicated test class for fiber-dependent logic (e.g., AsyncServiceTest).
  3. Bootstrap integration:
    • Extend PHPUnit\Framework\TestCase to initialize the ReactPHP loop in setUp().
    • Example:
      use React\EventLoop\Factory;
      use WyriHaximus\React\PHPUnit\RunTestsInFibersTrait;
      
      abstract class AsyncTestCase extends TestCase
      {
          use RunTestsInFibersTrait;
      
          protected function setUp(): void
          {
              $this->loop = Factory::create();
              parent::setUp();
          }
      
          protected function tearDown(): void
          {
              $this->loop->stop();
              parent::tearDown();
          }
      }
      
  4. Sequencing:
    • Run fiber tests last in the test suite to avoid loop conflicts.
    • Use --group async in PHPUnit to separate them from synchronous tests.

Compatibility:

  • PHPUnit 12+: Required by the package (Laravel 10+ supports this).
  • ReactPHP 2.0+: Must align with Laravel’s react/async version (if used).
  • No conflicts: Avoid mixing fiber tests with Laravel’s async tools (e.g., queues). Use mock services for dependencies that rely on Laravel’s async stack.

Operational Impact

Maintenance:

  • High overhead: Requires manual isolation of fiber tests to prevent conflicts with Laravel’s test lifecycle.
  • Dependency management: Must track ReactPHP and PHPUnit versions separately from Laravel’s constraints.
  • Debugging: Fiber-related errors (e.g., timeouts, leaks) are harder to diagnose in Laravel’s synchronous context.

Support:

  • Limited community: No active GitHub discussions or Stack Overflow tags for this package.
  • Laravel-specific issues: No documentation or examples for Laravel integration.
  • Workarounds: Teams may need to fork the package to add Laravel compatibility (e.g., handling service providers).

Scaling:

  • Performance: Fibers add overhead to test execution (event loop setup/teardown per test).
  • Parallelization: PHPUnit’s parallel testing may fail if fibers share global state (e.g., static services).
  • CI/CD: Requires separate test jobs for fiber tests to avoid loop conflicts.

Failure modes:

  1. Silent fiber leaks: Unclosed fibers may consume memory, causing OOM errors in CI.
  2. Test flakiness: Race conditions in fibers could produce intermittent failures.
  3. Database corruption: Fibers bypassing Laravel’s transaction middleware may leave inconsistent data.
  4. Loop conflicts: Running fiber tests alongside Laravel’s async workers (e.g., queues) risks deadlocks.

Ramp-up:

  • Team training: Requires education on ReactPHP fibers, event loops, and their interaction with Laravel.
  • Documentation gap: No Laravel-specific guides; teams must infer usage from ReactPHP examples.
  • Onboarding cost: Initial setup (custom test classes, loop isolation) adds 2–4 weeks of effort for a small team.
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.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata