php - Behat:如何清理场景中创建的数据库记录

标签 php symfony behat

我有以下情况:

    @mink:selenium2
  Scenario: Login
    Given there are the following users:
      | username | password | email               |
      | admin    | 1234     | <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="79181d141017390a161a1018151a180b571a1614" rel="noreferrer noopener nofollow">[email protected]</a> |
    When I am on "/login"
    And I fill in "username" with "admin"
    And I fill in "password" with "1234"
    And I press "Login"
    Then I should be on "/admin"

所以我想有一个 cleanupUsers 作为 @AfterScenario ,我可以清理场景中插入的任何内容。那么如何访问用户的TableNode呢?

最佳答案

您可以将您的用户保存在私有(private)属性(property)中,以便您稍后可以在 a hook 中访问它们:

private $users;

/**
 * @Given there are the following users:
 */
public function thereAreFollowingUsers(TableNode $table)
{
    $this->users = $table;

    // ...
}

/**
 * @AfterScenario
 */
public function cleanupUsers(AfterScenarioScope $scope)
{
    if (null !== $this->users) {
        // do the cleanups
        // ...

        // reset the property
        $this->users = null;
    }
}

关于php - Behat:如何清理场景中创建的数据库记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32456579/

相关文章:

php - OpenEMR安装错误步骤3

symfony2 达到最大函数嵌套级别 '100',中止!与学说事件监听器

使用 asset_url 进行 Jquery UI Assets 管理

php - 使用 Behat 3 和 Mink 1.5 的页面对象扩展引发异常

php - 暂时禁用 OPCache

php - 从多维数组中获取值的总和

JavaScript 变量在 Laravel 中不起作用

symfony - 在 Symfony 中转换表单字段值

PHPUnit & Behat;补充还是替代?

symfony - symfony2.4 中的 Behat 3(学说访问)