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