Symfony2+Behat+Mink:我应该如何重构?
在这个教程中提出了这个文件系统:
XXXBundle
|---Features
| |----FeaturesContext.php
|---ProductCategoryRelation.feature
其中FeaturesContext.php是存储函数
//FeaturesContext.php
/**
* Feature context.
*/
class FeatureContext extends BehatContext
{
/**
* @Given /I have a category "([^"]*)"/
*/
public function iHaveACategory($name)
{
$category = new \Acme\DemoBundle\Entity\Category();
$category->setName($name);
...
并在 ProductCategoryRelation.feature 中建议编写功能和场景:
Feature: Product Category Relationship
In order to setup a valid catalog
As a developer
I need a working relationship
This being the feature, we now need the scenarios to be defined.
Scenario: A category contains a product
Given I have a category "Underwear"
...
但是如果我的应用程序正在成长,那么应该如何重构FeaturesContext.php?
in this tutorial is proposed this file system:
XXXBundle
|---Features
| |----FeaturesContext.php
|---ProductCategoryRelation.feature
where FeaturesContext.php is the file that stores the functions
//FeaturesContext.php
/**
* Feature context.
*/
class FeatureContext extends BehatContext
{
/**
* @Given /I have a category "([^"]*)"/
*/
public function iHaveACategory($name)
{
$category = new \Acme\DemoBundle\Entity\Category();
$category->setName($name);
...
And inside ProductCategoryRelation.feature is proposed to write the features and the scenarios:
Feature: Product Category Relationship
In order to setup a valid catalog
As a developer
I need a working relationship
This being the feature, we now need the scenarios to be defined.
Scenario: A category contains a product
Given I have a category "Underwear"
...
But if my app is growing up, how should refactor for example FeaturesContext.php?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用子上下文将步骤定义拆分为多个上下文类:http:// docs.behat.org/guides/4.context.html#using-subcontexts
You might use subcontexts to split step definitions into multiple context classes: http://docs.behat.org/guides/4.context.html#using-subcontexts