2016-08-23 94 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

相關問題