kix / behat-sf2-service-generator
Behat Symfony2 服务生成器
0.1.0
2014-11-20 07:46 UTC
Requires
- php: >=5.4
- kix/behat-exception-listener: ~0.1
This package is auto-updated.
Last update: 2024-09-14 02:56:53 UTC
README
这是一个 Behat 扩展,它可以捕获对未定义的 Symfony 服务的调用,并运行 PHPSpec 来描述它们。
安装
只需运行以下命令
composer require kix/behat-sf2-service-generator "~0.1"
然后,在你的 behat.yml
中启用扩展
default:
# ...
extensions:
Kix\Symfony2ServiceExtension\Symfony2ServiceExtension: ~
现在,当你尝试访问一个不存在的服务时,你会被询问是否要为其生成一个类。同时,也会在控制台输出一个方便的 YAML 配置。以下是一个快速预览。
Feature: Generating Symfony services
Scenario: Creating a service when a ServiceNotFoundException is caught
When I run behat
And my step tries to get a service that doesn't exist
Then a shiny notification is displayed asking if I want to generate it
<?php
class FeatureContext implements Context, SnippetAcceptingContext
{
// Note I'm using Symfony2Extension here:
use \Behat\Symfony2Extension\Context\KernelDictionary;
/**
* 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()
{
}
/**
* @When I run behat
*/
public function iRunBehat()
{
// do nothing
}
/**
* @When my step tries to get a service that doesn't exist
*/
public function myStepTriesToGetAServiceThatDoesnTExist()
{
$this->getContainer()->get('my_bundle.kitten_provider');
}
}
然后,就完成了