vircom / behat3-zendframework3-extension
Behat Zend Framework 3 集成扩展
1.0.0
2017-04-17 07:33 UTC
Requires
- php: >=7.0
- behat/behat: ^3.3
- zendframework/zend-mvc: ^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.1
- leanphp/phpspec-code-coverage: ^3.1
- phpmd/phpmd: ^2.6
- phpspec/phpspec: ^3.2
This package is auto-updated.
Last update: 2024-08-27 23:44:24 UTC
README
本包为使用 Zend Framework 3 库开发的应用程序提供基础实现,以便进行测试。它可以将您的应用程序中声明的服务传递到 Behat 上下文文件。
安装
composer require vircom/behat3-zendframework3-extension
使用方法
创建 behat.yml 文件
在项目根目录下,创建 behat.yml 文件并添加以下内容,或者将此代码添加到根目录下现有的文件中
default: extensions: VirCom\Behat3ZendFramework3Extension: configuration_path: /config/application.config.php
参数
- configuration_path - 主 Zend Framework 3 配置文件路径。默认为:/config/application.config.php。
创建特征上下文文件
只需运行以下命令
vendor/bin/behat --init
现在,Behat 为您的第一个上下文文件生成内容
features/bootstrap/FeatureContext.php
将其内容修改为
<?php use Behat\Behat\Context\Context; use Behat\Gherkin\Node\PyStringNode; use Behat\Gherkin\Node\TableNode; use Zend\EventManager\EventManagerInterface; /** * Defines application features from the specific context. */ class FeatureContext implements Context { /** * Initializes context. * * Every scenario gets its own context instance. * You can also pass arbitrary arguments to the * context constructor through behat.yml. */ public function __construct(EventManagerInterface $eventManager) { echo get_class($eventManager); } }
创建示例特征文件
将以下文本放入文件中
features/example.feature
Feature: Product basket
In order to buy products
As a customer
I need to be able to put interesting products into a basket
在 behat.yml 文件中配置服务注入
配置上下文
default: suites: default: contexts: - FeatureContext: eventManager: '@EventManager' extensions: VirCom\Behat3ZendFramework3Extension: configuration_path: /config/application.config.php
每个定义的上下文参数,如果以 @
字符开头,则将解析为匹配的服务实例。否则,将返回原始参数作为字符串。
例如,可以注册任何自定义服务
My\Application\Namespace\ExampleService