如何在Behat中生成网址

Mic*_*ter 1 symfony behat mink

我已经开始使用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"
Run Code Online (Sandbox Code Playgroud)

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

Ino*_*ryy 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());
}
Run Code Online (Sandbox Code Playgroud)