friends-of-behat/service-container-extension

允许在Behat容器内声明自定义服务,而无需编写扩展。

v1.1.0 2020-11-05 21:29 UTC

This package is auto-updated.

Last update: 2024-09-06 05:24:52 UTC


README

允许在Behat容器内声明自定义服务,而无需编写扩展。

使用方法

  1. 安装它

    $ composer require friends-of-behat/service-container-extension --dev
  2. 启用此扩展并配置Behat以使用它

    # behat.yml
    default:
        # ...
        extensions:
            FriendsOfBehat\ServiceContainerExtension:
                imports:
                    - "features/bootstrap/config/services.xml"
                    - "features/bootstrap/config/services.yml"
                    - "features/bootstrap/config/services.php"
  3. 编写服务文件定义

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