如何(在何处)定义Behat / Mink中的特征步骤

时间:2013-08-31 10:42:19

标签: yii bdd behat mink

我遇到了在Yii框架中为Behat和Mink设置定义自己的BDD功能步骤的问题。

我按照MinkExtension-example的说明成功安装了Behat with Mink扩展程序。

毕竟,我在 myapp / private_html / 中有我的文件夹的以下结构(省略了一些深层嵌套的文件夹):

├───bin
├───commands
│   └───shell
├───components
├───config
├───controllers
├───features
│   ├───bootstrap
│   └───php54_bootstrap
├───models
├───tests
├───vendor
│   ├───behat
│   │   ├───behat
│   │   │   ├───bin
│   │   │   ├───features
│   │   │   │   ├───annotations
│   │   │   │   ├───bootstrap
│   │   │   │   └───closures
└───views

在上述链接MinkExtension-example中作为示例提供的功能可以正常运行。但是当我定义自己的步骤时

  Scenario: presence of menu items
    Given I am on "/"
    Then I should see the following: "Home, About, Contact"

我得到了

1 scenario (1 undefined)
2 steps (1 passed, 1 undefined)
0m2.288s

提出建议

You can implement step definitions for undefined steps with these snippets:

/**
 * @Then /^I should see the following: "([^"]*)"$/
 */
public function iShouldSeeTheFollowing($arg1)
{
    throw new PendingException();
}

问题是:我应该把这段代码放在哪里?我试过把它放进去

myapp\private_html\features\bootstrap\FeatureContext.php

以及

myapp\private_html\vendor\behat\behat\features\bootstrap\FeatureContext.php 

但步骤仍然未定义。

那么,应该在哪里定义步骤?

2 个答案:

答案 0 :(得分:1)

您永远不必更改供应商的代码(我想您正在使用作曲家)。不是你的代码。

您必须将代码添加到features \ bootstrap \ FeatureContext.php。

也许问题是你的FeatureContext类不扩展MinkContext而是扩展BehatContext。你会在FeatureContext的文件中找到评论。将FeatureContext的父类从BehatContext更改为MinkContext。

最后,要查看上下文可以看到的所有句子,请运行“./bin/behat -dl”。如果在更改上下文之前运行此命令,则可以看到几乎没有句子。

答案 1 :(得分:0)

如果你想通过behat mink看到预定义的步骤和功能。

vendor/bin/behat -dl 

您将看到可以用于您网站的步骤。

现在已经是你可以使用的步骤

Scenario: presence of menu items
 Given I am on "/"
 Then I should see "Home, About, Contact"
 Theres nothing like "Then I should see following".