Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 行为:如何清理场景中创建的数据库记录_Php_Symfony_Behat - Fatal编程技术网

Php 行为:如何清理场景中创建的数据库记录

Php 行为:如何清理场景中创建的数据库记录,php,symfony,behat,Php,Symfony,Behat,我有以下情况: @mink:selenium2 Scenario: Login Given there are the following users: | username | password | email | | admin | 1234 | admin@socialcar.com | When I am on "/login" And I fill in "username" with

我有以下情况:

    @mink:selenium2
  Scenario: Login
    Given there are the following users:
      | username | password | email               |
      | admin    | 1234     | admin@socialcar.com |
    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呢?

根据:hooks“也可以访问您在场景中设置的任何对象属性”


因此,我认为您只需要将
TableNode
(或者更好,只需将创建的用户ID)保存在
代码中上下文类的属性中,因为有以下用户
步骤,然后在
cleanupupusers

中使用它,您可以将用户保存在私有属性中,以便以后可以在以下位置访问他们:

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;
    }
}