friends-of-behat / context-service-extension
Allows to declare and use contexts services in scenario scoped container.
Installs: 561 773
Dependents: 59
Suggesters: 1
Security: 0
Stars: 115
Watchers: 3
Forks: 7
Open Issues: 1
Requires
- php: ^7.1
- behat/behat: ^3.1
- symfony/dependency-injection: ^3.4|^4.1
Requires (Dev)
Suggests
- friends-of-behat/cross-container-extension: ^1.0
- ocramius/proxy-manager: ^2.0
- symfony/proxy-manager-bridge: ^3.4|^4.2
README
This library is deprecated! It will not be supported anymore - if you're using it with CrossContainerExtension v1 and SymfonyExtension v1, please consider an upgrade to SymfonyExtension v2.
Allows to declare and use contexts services in scenario scoped container.
Usage
-
Install it:
$ composer require friends-of-behat/context-service-extension --dev
-
Enable and configure context service extension in your Behat configuration:
# behat.yml default: # ... extensions: FriendsOfBehat\ContextServiceExtension: imports: - "features/bootstrap/config/services.xml" - "features/bootstrap/config/services.yml" - "features/bootstrap/config/services.php"
-
Inside one of those files passed to configuration above, create a service tagged with
fob.context_service
.<!-- features/bootstrap/config/services.xml --> <?xml version="1.0" encoding="UTF-8" ?> <container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://symfony.com/schema/dic/services"> <services> <service id="acme.my_context" class="Acme\MyContext"> <tag name="fob.context_service" /> </service> </services> </container>
# features/bootstrap/config/services.yml services: acme.my_context: class: Acme\MyContext tags: - { name: fob.context_service }
// features/bootstrap/config/services.php use Symfony\Component\DependencyInjection\Definition; $definition = new Definition(\Acme\MyContext::class); $definition->addTag('fob.context_service'); $container->setDefinition('acme.my_context', $definition);
-
Configure your suite to use
acme.my_context
context service (note contexts_services key instead of contexts):# behat.yml default: # ... suites: default: contexts_services: - acme.my_context
-
Have fun with your contexts defined in DI container as services! 🎉