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

发布于 2024-12-07 11:31:12 字数 1024 浏览 0 评论 0原文

在这个教程中提出了这个文件系统:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少跟Wǒ拽 2024-12-14 11:31:12

您可以使用子上下文将步骤定义拆分为多个上下文类: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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文