Allows injecting services from a container created using lcobucci/di-builder
in a Behat context.
Package is available on Packagist, you can install it using Composer.
composer require --dev lcobucci/behat-di-builder-extension
You must first enable the extension on your behat configuration file:
default:
# ...
extensions:
Lcobucci\DependencyInjection\Behat\BuilderExtension: ~
Then enable the use of the test container (create by the extension) in the suite configuration:
default:
suites:
my-suite:
services: "@test_container"
extensions:
Lcobucci\DependencyInjection\Behat\BuilderExtension: ~
And finally inject the services into your contexts
default:
suites:
my-suite:
services: "@test_container"
contexts:
- My\Lovely\Context:
- "@my_service"
extensions:
Lcobucci\DependencyInjection\Behat\BuilderExtension: ~
You can provide the following parameters to the extension to better configure it:
- name: if you already have an extension using
test_container
- container_builder: if your application already uses
lcobucci/di-builder
and you want to use it (instead of a blank container builder) - packages: so that you can add/override service definitions for testing
Your behat.yml
would look like this with those settings:
default:
suites:
my-suite:
services: "@my_container"
contexts:
- My\Lovely\Context:
- "@my_service"
extensions:
Lcobucci\DependencyInjection\Behat\BuilderExtension:
name: "my_container"
container_builder: "config/container_builder.php"
packages:
My\DIBuilder\Package: ~
My\DIBuilder\PackageWithConstructorArguments:
- "one"
- "two"