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

Service Container Extension Laravel Package

friends-of-behat/service-container-extension

Declare custom Symfony DI services in Behat without writing a full extension. Import XML/YAML/PHP service definition files via behat.yml so your contexts and helpers can be wired through the Behat service container.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Accelerating Test-Driven Development (TDD) in Laravel: Enables teams to rapidly prototype and iterate on Behat test suites by injecting custom services (e.g., mock APIs, test repositories, or domain-specific utilities) without building full extensions. Reduces the cognitive load for QA engineers and developers collaborating on BDD workflows.

    • Example: Inject a TestPaymentGateway into a PaymentFeatureContext to validate edge cases without touching production code.
  • Decoupling Test Infrastructure from Laravel’s Core: Supports a "build vs. buy" decision by avoiding custom extension development for test-specific needs. Aligns with Laravel’s philosophy of separation of concerns (e.g., test services vs. production services).

    • Use Case: Replace manual new TestUserFactory() calls with container-managed instances to enforce consistency and reduce duplication.
  • Scaling Behat for Complex Laravel Applications: Justifies investment in Behat for projects with modular architectures (e.g., microservices, multi-tenancy) by providing a maintainable way to extend test coverage without refactoring core test logic.

    • Roadmap Tie-In: Enables incremental adoption of Behat for new feature areas (e.g., adding BDD tests for a new payment module) without upfront extension development.
  • Use Cases in Laravel Ecosystem:

    • Mocking External Dependencies: Dynamically inject mocks for third-party services (e.g., Stripe, Twilio) to isolate tests from live systems.
      • Example: Define stripe_mock in services.yml and inject it into a SubscriptionFeatureContext.
    • Reusable Test Utilities: Share domain-specific helpers (e.g., TestDatabaseSeeder, TestAuthHelper) across feature contexts without global state pollution.
      • Example: Centralize a TestUserFactory in services.php and reuse it in UserManagementContext and ProfileContext.
    • CI/CD Pipeline Services: Inject environment-specific services (e.g., TestSlackNotifier, TestS3Uploader) for test reporting or artifact handling.
      • Example: Configure services.yml to use a TestMailer that logs emails instead of sending them in CI.
    • Laravel-Specific Testing Patterns: Aligns with Laravel’s testing helpers (e.g., createMock(), Mockery) but provides tighter DI integration for complex scenarios.
      • Example: Use the container to bind a TestHttpClient that wraps Laravel’s Http facade for controlled API testing.

When to Consider This Package

  • Adopt When:

    • Your Laravel + Behat project requires custom services that aren’t covered by existing extensions (e.g., Behat\MinkExtension, Behat\SymfonyExtension).
    • You’re frequently writing manual service instantiations (e.g., new TestService()) in step definitions or hooks, indicating a pattern for abstraction.
    • Your team prioritizes developer velocity over long-term maintenance of custom extensions, especially for one-off or niche use cases (e.g., integrating with a proprietary SDK or internal microservice).
    • You’re already using Symfony’s DI component in Laravel (via Illuminate/Container) and want to leverage familiar syntax (XML/YAML/PHP) for test configurations.
    • You need to scale Behat test coverage for complex Laravel features (e.g., payment workflows, multi-tenancy) without bloating the test suite with custom extensions.
    • Your CI/CD pipeline requires dynamic test services (e.g., mock databases, test notifications) that can’t be easily configured via Laravel’s native testing helpers.
  • Look Elsewhere If:

    • You need deep Behat lifecycle hooks (e.g., modifying BeforeScenario, AfterFeature), which require a full extension (e.g., Behat\HookExtension).
    • Your use case involves modifying Behat’s core behavior (e.g., altering step definition resolution or context initialization).
    • You’re heavily invested in Laravel’s native testing tools (e.g., Pest, PHPUnit) and prefer not to introduce Behat-specific dependencies.
    • Maintenance risk is a concern: The package is unmaintained post-2020, and Laravel/Behat have evolved since (e.g., PHP 8.2+, Behat 4+). Evaluate if the trade-off for reduced boilerplate justifies potential future forks or replacements (e.g., migrating to Behat’s native DI support or Laravel’s Testing facade).
    • Your team lacks Symfony DI familiarity, as the package requires XML/YAML/PHP configuration (though Laravel’s config/ and app/Providers/ may mitigate this).
    • You’re using Laravel’s Testing facade extensively and find it sufficient for mocking (e.g., createMock(), fake()). This package adds value primarily for complex DI scenarios.

How to Pitch It (Stakeholders)

For Executives:

*"This package lets our QA and development teams plug in custom test services—like mock payment processors, test database seeders, or CI-specific notifiers—into our Behat tests without building custom extensions from scratch. It’s like using Laravel’s service container for tests, but tailored for Behat.

Why it matters:

  • Faster test development: Instead of spending days writing a custom extension to mock our Stripe integration, we’d configure it in 30 minutes using familiar YAML/PHP syntax.
  • Reduces technical debt: Avoids the maintenance burden of custom extensions for one-off needs, freeing up engineering time for higher-value work.
  • Scales with Laravel: Since it uses Symfony’s DI (which Laravel already relies on), it integrates seamlessly with our existing stack.

Impact:

  • Ship features faster: Accelerate BDD workflows for complex modules (e.g., subscriptions, multi-tenancy).
  • Improve test reliability: Isolate tests from external dependencies with clean mocks.
  • Align with Laravel’s ecosystem: No reinventing the wheel—just extend what we already use.

Risk:

  • The package is unmaintained, but we can mitigate this by treating it as a short-term gain and planning to migrate to Laravel’s native testing tools or a maintained alternative if needed.

Ask:

  • Should we pilot this for our next high-priority feature (e.g., payment workflows) to validate the time savings?"*

For Engineering (Developers/QA):

*"This package lets us inject custom services into Behat’s container using Symfony’s DI syntax (XML/YAML/PHP), which we’re already familiar with from Laravel. It’s a lightweight way to avoid writing custom extensions for simple use cases.

When to Use It:

  • You need to mock external services (e.g., Stripe, Twilio) without polluting global state.
  • You want to share test utilities (e.g., TestUserFactory, TestDatabaseSeeder) across feature contexts.
  • You’re tired of manually instantiating services in step definitions (e.g., new TestApiClient()).

How It Works:

  1. Install it via Composer (--dev scope).
  2. Configure behat.yml to import your service definitions (e.g., services.yml in features/bootstrap/config/).
  3. Define services in familiar formats:
    # features/bootstrap/config/services.yml
    services:
        test.payment_gateway:
            class: App\Tests\Services\MockPaymentGateway
            arguments: ['@test.logger']
    
  4. Inject services into contexts or hooks:
    class PaymentFeatureContext {
        public function __construct(private MockPaymentGateway $paymentGateway) {}
    }
    

Pros:

  • No extension dev overhead: Avoid writing a full Behat extension for simple needs.
  • Familiar syntax: Uses Symfony DI (same as Laravel’s container).
  • Isolated: Test services don’t leak into Laravel’s production container.

Cons/Risks:

  • Unmaintained: Last release in 2020. Use for short-term gains or plan to migrate.
  • Symfony DI knowledge required: If your team isn’t familiar with XML/YAML/PHP config, there’s a learning curve.
  • Laravel-specific: Best fit for Laravel projects using Behat; less relevant for vanilla PHP.

Recommendation:

  • Try it for: Mocking APIs, sharing test utilities, or CI-specific services.
  • Avoid for: Deep Behat hooks or modifying core behavior (use a full extension instead).
  • Plan for: Monitor Laravel/Behat updates and reassess in 6–12 months.

Example Workflow: Instead of this:

// Manual instantiation (messy)
$client = new TestApiClient(config('test.api'));

Do this:

# services.yml
services:
    test.api_client:
        class: App\Tests\Services\TestApiClient
        arguments: ['%env(TEST_API_URL)%']
// Clean injection
class ApiFeatureContext {
    public function __construct(private TestApiClient $client) {}
}
```*

---
### **For Technical Leads/Architects**:
*"This package addresses a gap in Laravel’s Behat integration by providing a **Symfony DI-compatible service container extension** for Behat. It’s particularly valuable for teams
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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor