friends-of-behat / service-container-extension
允许在Behat容器内声明自定义服务,而无需编写扩展。
v1.1.0
2020-11-05 21:29 UTC
Requires
- php: ^7.3 || ^8.0
- behat/behat: ^3.4
Requires (Dev)
- friends-of-behat/test-context: ^1.2
- vimeo/psalm: 4.1.1
README
允许在Behat容器内声明自定义服务,而无需编写扩展。
使用方法
-
安装它
$ composer require friends-of-behat/service-container-extension --dev
-
启用此扩展并配置Behat以使用它
# behat.yml default: # ... extensions: FriendsOfBehat\ServiceContainerExtension: imports: - "features/bootstrap/config/services.xml" - "features/bootstrap/config/services.yml" - "features/bootstrap/config/services.php"
-
编写服务文件定义
<!-- 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));