2016-08-23 90 views
1

我在我的FeatureContext.php中有一个函数,它使用@AfterScenario来清理在测试过程中创建的假数据库条目。我想添加一个@debug标签到特定的场景,告诉函数不要删除为该场景创建的条目,如果该标签存在。在Behat,有没有测试特定标签的方法?

/** 
* Deletes the records created during the scenarios. 
* @AfterScenario 
*/ 
public function cleanDB(AfterScenarioScope $scope) 
{ 
    // if [email protected] present 
     // delete files from database 
    // end if 
} 
+0

behat是什么版本? – lauda

+0

没有尝试过使用标签,但它应该能够获得场景标题,或设置一些变量并根据该变量进行决定。 – lauda

+0

@lauda,Behat 3.1 – zkent

回答

1

@劳达的答案让我接近,我想通了其余的。

我使用Behat的场景对象的hasTag()函数。

/** 
* Deletes the NCP records created during the scenarios. 
* @AfterScenario 
*/ 
public function cleanDB(AfterScenarioScope $scope) 
{ 
    // if the @debug tag is set, ignore 
    if (!$scope->getScenario()->hasTag("debug")) { 
     // delete records from database 
    } 
} 

如果我用@debug装饰场景,我可以测试它并更改我的功能。

@debug 
Scenario: do the thing 
    ... 
+0

如果标签设置在功能上,这不起作用。你必须这样做: 'in_array('debug',array_merge($ scope-> getFeature() - > getTags(),$ scope-> getScenario() - > getTags()));' – hackel

相关问题