1

我已经开始使用 BehatBundle 和 MinkBundle 测试我的 Symfony2 应用程序。现在我正在尝试编写检查某些页面响应的场景。这些页面可通过包含实体 ID 的 URL 访问。现在我想知道如何知道 Doctrine 插入了哪个 ID。

这是一个例子:

Background:
    Given There is no "Category" in database
      And I have a category "Todo Lists"

  Scenario: The category can be viewed
    Given I am on "/category/<id here>"
     Then I should see "Todo Lists"

问题是我不知道如何找出插入的类别的 ID。Behat / Mink 有可能吗?

4

2 回答 2

5

在您的上下文类中添加一个自定义步骤,如下所示:

/**
 * @Given /^I am on the "([^"]*)" category page$/
 * @When /^I go to the "([^"]*)" category page$/
 */
public function gotoCategoryPage($categoryName)
{
    // find category by $categoryName here
    // $category = ...

    $s = $this->getSession();
    $s->visit($this->locatePath('/category/'.$category->getId());
}
于 2012-02-09T13:58:31.790 回答
0

You can modify your Given statement with something like:

Given There is no "Category" in database
  And I have a category "Todo lists" with id "1"

Scenario: The category can be viewed
Given I am on "/category/1"
 Then I should see "Todo Lists"

And then set id for category as you do for name already.

于 2012-02-09T11:55:35.083 回答