如何在 Behat 中生成 url

发布于 01-04 16:45 字数 447 浏览 4 评论 0原文

我已经开始使用 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 可能做到这一点吗?

I have started to test my Symfony2 application with the BehatBundle and MinkBundle. Now I am trying to write scenarios that check the response of some pages. These pages are accessible via an URL which contain the ID of the entities. Now I'm wondering how to know which ID was inserted by Doctrine.

Here's an example:

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"

The problem is I don't know how to find out the ID of the category inserted. Is that possible with Behat / Mink?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

狼亦尘2025-01-11 16:45:45

将自定义步骤添加到上下文类中,如下所示:

/**
 * @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());
}

Add a custom step into your context class, something like this:

/**
 * @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());
}
无边思念无边月2025-01-11 16:45:45

您可以修改您的 Given 语句,如下所示:

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"

然后为类别设置 id,就像为名称所做的那样。

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.

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