-
-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a trait for determining current scenario tags.
- Fixes #468
- Loading branch information
Showing
2 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace Drupal\DrupalExtension; | ||
|
||
use Behat\Behat\Hook\Scope\BeforeScenarioScope; | ||
use Behat\Behat\Hook\Scope\StepScope; | ||
use Behat\Gherkin\Node\ScenarioInterface; | ||
|
||
/** | ||
* A workaround to discover the current scenario. | ||
* | ||
* @see https://github.com/Behat/Behat/issues/653 | ||
* @see https://github.com/Behat/Behat/issues/650 | ||
* | ||
* The solution is documented in this issue: https://github.com/Behat/Behat/issues/703#issuecomment-86687563 | ||
* | ||
* @package Drupal\DrupalExtension | ||
*/ | ||
trait ScenarioTagTrait | ||
{ | ||
|
||
/** | ||
* The registered scenario. | ||
* | ||
* @var ScenarioInterface | ||
*/ | ||
protected $currentScenario; | ||
|
||
/** | ||
* Register the scenario. | ||
* | ||
* @param BeforeScenarioScope $scope | ||
* | ||
* @BeforeScenario | ||
*/ | ||
public function registerScenario(BeforeScenarioScope $scope) | ||
{ | ||
$this->currentScenario = $scope->getScenario(); | ||
} | ||
|
||
/** | ||
* @return ScenarioInterface | ||
*/ | ||
protected function getScenario() | ||
{ | ||
return $this->currentScenario; | ||
} | ||
|
||
/** | ||
* Get all tags for the current scenario. | ||
* | ||
* @param StepScope $scope | ||
* @return string[] | ||
*/ | ||
protected function getCurrentScenarioTags(StepScope $scope) | ||
{ | ||
$featureTags = $scope->getFeature()->getTags(); | ||
$scenarioTags = $this->getScenario()->getTags(); | ||
return array_merge($featureTags, $scenarioTags); | ||
} | ||
} |