I have a function in my FeatureContext.php that uses @AfterScenario to clean up fake database entries created during the test. I'd like to add a @debug tag to a particular scenario tell the function to NOT delete the entries created for that scenario if the tag is present.
/**
* Deletes the records created during the scenarios.
* @AfterScenario
*/
public function cleanDB(AfterScenarioScope $scope)
{
// if !@debug present
// delete files from database
// end if
}
@lauda's answer got me close and I figured out the rest.
I used the hasTag() function of Behat's scenario object.
/**
* 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
}
}
If I decorate the scenario with @debug, I can test for that and change my functionality.
@debug
Scenario: do the thing
...