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

Common Contexts Laravel Package

behat/common-contexts

Abandoned Behat 2.x add-on providing reusable subcontexts with extra steps/hooks. Includes contexts like SymfonyMailerContext, DoctrineFixturesContext, and SymfonyDoctrineContext for loading fixtures, purging DB, and resetting schema in Symfony-based suites.

View on GitHub
Deep Wiki
Context7

Integration Approach

Stack Fit

  • Incompatible with Laravel’s Ecosystem: The package is hardcoded for Symfony 2.x + Behat 2.x, making it a poor fit for Laravel projects. Key conflicts:
    • Dependency Injection: Relies on Symfony’s ContainerInterface (e.g., $this->kernel->getContainer()), which Laravel replaces with its own container or no DI in tests.
    • Testing Framework: Behat 2.x’s context system (useContext(), getSubcontext()) is deprecated in Behat 3.x+ and lacks Laravel integration (e.g., no create() or assertDatabaseHas() compatibility).
    • ORM/Database: Assumes Doctrine ORM v2.x, while Laravel uses Eloquent, DBAL, or Doctrine v3+ (with different APIs for fixtures, schema management, and purging).
    • Mailer: SymfonyMailerContext targets Symfony 2.x’s SwiftmailerBundle, whereas Laravel uses its Mail facade (Mail::fake() for testing).
  • Potential Partial Use Cases:
    • Legacy Hybrid Apps: If a Laravel project also maintains a Symfony 2.x microservice using Behat 2.x, the package might be usable there—but this is a niche edge case.
    • Learning Reference: The package’s pattern of reusable contexts could inspire custom Laravel/Behat 3.x implementations (e.g., shared fixture loading logic).

Migration Path

Option 1: Abandon (Recommended)

  • Action: Replace all functionality with Laravel-native or modern Behat 3.x alternatives.
  • Steps:
    1. Fixtures: Use Laravel’s built-in DatabaseSeeder, Factory classes, or packages like orchestra/testbench for Doctrine.
    2. Mail Testing: Replace SymfonyMailerContext with Mail::fake() or spatie/laravel-mail-trap.
    3. Schema Reset: Use Artisan::call('migrate:fresh'), DatabaseMigrations, or sail for Docker-based resets.
    4. Behat 2.x: Migrate to Behat 3.x+ (if needed) or abandon Behat for Pest PHP or PHPUnit (Laravel’s default).
  • Complexity: Low (no forking, minimal refactoring).
  • Tools:
    • Fixtures: laravel-shift/database-seeder, fakerphp/faker.
    • Mail: Mail::fake(), spatie/laravel-mail-trap.
    • Schema: php artisan migrate:fresh --seed.

Option 2: Fork and Modernize (High Risk)

  • Action: Fork the package and adapt it for Laravel/Behat 3.x.
  • Steps:
    1. Update Behat: Replace Behat 2.x dependencies with behat/behat:^3.0.
    2. Replace Symfony DI: Rewrite container access to use Laravel’s app() or Behat 3.x’s service injection.
    3. Adapt Doctrine: Replace ORMPurger, ORMExecutor with Eloquent/DBAL equivalents (e.g., Schema::dropAllTables(), Factory::new()).
    4. Laravel Mailer: Replace SymfonyMailerContext with a context using Mail::fake().
    5. Test Integration: Ensure contexts work in Laravel’s test environment (e.g., php artisan test).
  • Complexity: Very High (requires deep knowledge of both Laravel and Behat internals).
  • Example Fork Structure:
    // laravel-common-contexts/src/LaravelMailContext.php
    use Behat\Testwork\Hook\Scope\ScenarioScope;
    use Illuminate\Support\Facades\Mail;
    
    class LaravelMailContext implements Context
    {
        public function __construct(private ScenarioScope $scope) {}
    
        /**
         * @Given I have sent an email to :email
         */
        public function iHaveSentAnEmail(string $email): void
        {
            Mail::fake();
            Mail::to($email)->send(new TestMail());
            Mail::assertSent(TestMail::class);
        }
    }
    
  • Risks:
    • Maintenance Overhead: No upstream support; future Laravel/Behat updates may break compatibility.
    • Testing Effort: Requires extensive test suites to validate the forked contexts.
    • Opportunity Cost: Time spent forking could be used to build custom Laravel-specific solutions.

Option 3: Hybrid Integration (Symfony 2.x Subsystem)

  • Action: Use the package only for a Symfony 2.x subsystem within a Laravel app (e.g., via a microservice or legacy module).
  • Steps:
    1. Isolate the Symfony 2.x subsystem in a separate Docker container or subdirectory.
    2. Configure Behat 2.x only for that subsystem (e.g., using behat/behat:2.x in a composer.json scoped to the Symfony module).
    3. Expose APIs (e.g., REST) to Laravel for testing.
  • Complexity: Medium-High (requires infrastructure changes).
  • Use Case: Rare; only justified for critical legacy dependencies.

Compatibility

Component Laravel Compatibility Workaround
Behat 2.x Contexts ❌ No Fork + rewrite for Behat 3.x
SymfonyMailerContext ❌ No (Swiftmailer) Use Mail::fake()
DoctrineFixturesContext ⚠️ Partial (ORM v2) Use Eloquent Factories or Testbench
SymfonyDoctrineContext ❌ No (Symfony DI) Artisan::call('migrate:fresh')

Sequencing

  1. Assess Impact:
    • Audit all test suites using the package. Identify critical vs. non-critical contexts.
  2. Prioritize Replacement:
    • Start with non-critical contexts (e.g., email testing → Mail::fake()).
    • Replace fixtures with Laravel’s DatabaseSeeder or Factory.
  3. Deprecate Gradually:
    • Remove package dependencies in phases (e.g., per feature module).
    • Update CI/CD pipelines to fail builds using the abandoned package.
  4. Document Alternatives:
    • Create a migration guide for the team (e.g., "Replace SymfonyDoctrineContext with Artisan::call('migrate:fresh')").
  5. Fork as Last Resort:
    • Only fork if no modern alternative exists and the team has capacity to maintain it.

Operational Impact

Maintenance

  • High Risk: The package is abandoned, with:
    • No Security Updates: Underlying Behat 2.x/Symfony 2.x dependencies may have unpatched vulnerabilities.
    • No Bug Fixes: Issues (e.g., Doctrine ORM edge cases) will not be resolved upstream.
    • Fork Maintenance: If forked, the team must actively maintain the adapted contexts, including:
      • Updating for Laravel/Behat 3.x+ changes.
      • Patching Doctrine/Eloquent API drifts.
      • Testing against new Symfony/Laravel versions.
  • Laravel-Native Alternatives: Require minimal maintenance (e.g., Mail::fake() is updated by Laravel core team).

Support

  • Limited Community Support:
    • No active GitHub issues/PRs (repository is archived).
    • Stack Overflow/Forums: Most discussions are Behat 2.x-specific and irrelevant to Laravel.
  • Internal Support Burden:
    • Teams will need to reverse-engineer the package’s logic to debug issues.
    • No official documentation for Laravel integration.
  • Vendor Lock-In: Relying on an abandoned package increases technical debt and reduces hiring flexibility.

Scaling

  • Vertical Scaling Issues:
    • Performance: Behat 2.x contexts may not optimize for Laravel’s testing patterns (e.g., parallel tests with Pest).
    • Resource Usage: Doctrine ORM v2.x fixtures could bloat test suites compared to Eloquent Factories.
  • Horizontal Scaling:
    • CI/CD Impact: Running Behat 2.x in Laravel’s CI (e.g., GitHub Actions) may require custom Docker setups for Symfony 2.x dependencies.
    • Team Onboarding: New developers may struggle with the hybrid Behat/Symfony/Laravel stack.

Failure Modes

Failure Scenario Likelihood Impact Mitigation
Behat 2.x Deprecation High
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.
craftcms/url-validator
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony