solutiondrive/behat-symfony-dependency-injection-container-extension

Allows to load additional dependency injection config files for behat

v0.1.0 2018-03-06 16:22 UTC

This package is auto-updated.

Last update: 2024-10-19 20:01:06 UTC


README

Extension to load additional dependency injection config files for behat

Inspired by FriendsOfBehat/ServiceContainerExtension

Usage

  1. Install it:

    $ composer require solutiondrive/behat-symfony-dependency-injection-container-extension --dev
  2. Enable this extension and configure Behat to use it:

    # behat.yml
    default:
        # ...
        extensions:
            solutionDrive\BehatSymfonyDependencyInjectionContainerExtension:
                identifiers:
                    solutionDrive:
                        imports:
                            - "config/solutionDrive/services.xml"
                            - "config/solutionDrive/services.yml"
                            - "config/solutionDrive/services.php"
  3. Write services file definitions:

    <!-- config/solutionDrive/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_service" class="Acme\MyService" />
        </services>
    </container>
    # config/solutionDrive/services.yml
    services:
        acme.my_service:
            class: Acme\MyService
    // config/solutionDrive/services.php
    use Symfony\Component\DependencyInjection\Definition;
    
    $container->setDefinition('acme.my_service', new Definition(\Acme\MyService::class));