Symfony2 + Behat + Mink:我应该如何重构?

时间:2011-09-30 19:40:17

标签: symfony cucumber bdd

这个文件系统提出了tutorial中的

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呢?

1 个答案:

答案 0 :(得分:0)

您可以使用子上下文将步骤定义拆分为多个上下文类:http://docs.behat.org/guides/4.context.html#using-subcontexts