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

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

:radio: Allows to declare own services inside Behat container without writing an extension.

Frequently asked questions about Service Container Extension
Can I use this package with Laravel 10 and PHP 8.2+?
The package hasn’t been updated since 2020, so PHP 8.2+ and Laravel 10 compatibility isn’t guaranteed. Test in a staging environment first, or fork the package to patch any breaking changes in Symfony’s DI components.
How do I define a service that needs Laravel’s AppServiceProvider bindings?
This package only works within Behat’s container—it won’t access Laravel’s production services. For shared dependencies, manually pass Laravel’s bindings (e.g., via constructor arguments) or use a wrapper service defined in Behat’s config.
Will this work with Behat 4+ or only older versions?
The package was built for Behat 3.x, and Behat’s container API has evolved since then. If you’re on Behat 4+, check for deprecation warnings or consider a maintained fork like `behat/symfony-extension` for modern DI support.
Can I reuse Laravel’s config paths (e.g., %paths.config%) in behat.yml?
Yes! The package supports Laravel’s path variables (e.g., `%paths.config%/behat/services.yml`), so you can keep service definitions alongside Laravel’s existing config structure for consistency.
How do I inject a service into a Behat context or step definition?
Type-hint the service in your context’s constructor. For example, `public function __construct(private TestApiClient $client) {}` will automatically resolve the service if it’s defined in your imported YAML/XML/PHP config.
Is there a risk of service conflicts between Laravel and Behat?
No, this package operates in Behat’s isolated container. However, if you manually instantiate Laravel services (e.g., `new AppService()`) in Behat, they won’t be managed by the container, which could lead to inconsistencies.
Can I use this with Laravel’s Pest or PHPUnit instead of Behat?
This package is Behat-specific. For Pest/PHPUnit, consider Laravel’s built-in `bind()` method in `AppServiceProvider` or third-party packages like `orchestra/testbench` for test-specific DI.
How do I handle singleton vs. prototype services in Behat?
By default, services are singletons. For prototypes, define them explicitly in your YAML/XML/PHP config (e.g., `public: false` in YAML or `<prototype>` in XML). Document scoping rules in your team’s test conventions.
Do I need to install this in production or only in CI/dev?
Install it in `--dev` scope only. Ensure your CI pipeline runs `composer install --dev` before Behat tests to avoid missing dependencies.
What’s the best way to migrate from manual service instantiation to this package?
Start by identifying hardcoded services in your Behat tests (e.g., `new TestApiClient()`). Replace them incrementally: define the service in `services.yml`, update the context’s constructor, and refactor one test file at a time.
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.
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
spatie/laravel-javascript-views