-
-
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.
Merge pull request #510 from jhedstrom/tagtrait
Provide TagTrait to replace ScenarioTagTrait.
- Loading branch information
Showing
7 changed files
with
173 additions
and
7 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
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,46 @@ | ||
<?php | ||
|
||
namespace Drupal\DrupalExtension; | ||
|
||
use Behat\Behat\Hook\Scope\BeforeStepScope; | ||
|
||
/** | ||
* A workaround to discover the current feature. | ||
* | ||
* @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 | ||
*/ | ||
trait FeatureTrait | ||
{ | ||
|
||
/** | ||
* The registered feature. | ||
* | ||
* @var \Behat\Gherkin\Node\FeatureNode | ||
*/ | ||
protected $currentFeature; | ||
|
||
/** | ||
* Register the feature. | ||
* | ||
* This fires on a BeforeStep rather than a BeforeFeature since the latter | ||
* can only be called statically. | ||
* | ||
* @param \Behat\Behat\Hook\Scope\BeforeStepScope $scope | ||
* | ||
* @BeforeStep | ||
*/ | ||
public function registerFeature(BeforeStepScope $scope) | ||
{ | ||
$this->currentFeature = $scope->getFeature(); | ||
} | ||
|
||
/** | ||
* @return \Behat\Gherkin\Node\FeatureNode | ||
*/ | ||
protected function getFeature() | ||
{ | ||
return $this->currentFeature; | ||
} | ||
} |
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,43 @@ | ||
<?php | ||
|
||
namespace Drupal\DrupalExtension; | ||
|
||
use Behat\Behat\Hook\Scope\BeforeScenarioScope; | ||
|
||
/** | ||
* 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 | ||
*/ | ||
trait ScenarioTrait | ||
{ | ||
|
||
/** | ||
* The registered scenario. | ||
* | ||
* @var \Behat\Gherkin\Node\ScenarioInterface | ||
*/ | ||
protected $currentScenario; | ||
|
||
/** | ||
* Register the scenario. | ||
* | ||
* @param \Behat\Behat\Hook\Scope\BeforeScenarioScope $scope | ||
* | ||
* @BeforeScenario | ||
*/ | ||
public function registerScenario(BeforeScenarioScope $scope) | ||
{ | ||
$this->currentScenario = $scope->getScenario(); | ||
} | ||
|
||
/** | ||
* @return \Behat\Gherkin\Node\ScenarioInterface | ||
*/ | ||
protected function getScenario() | ||
{ | ||
return $this->currentScenario; | ||
} | ||
} |
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,35 @@ | ||
<?php | ||
|
||
namespace Drupal\DrupalExtension; | ||
|
||
/** | ||
* Helper methods to check the tags that are present on a feature or scenario. | ||
*/ | ||
trait TagTrait | ||
{ | ||
use FeatureTrait, ScenarioTrait; | ||
|
||
/** | ||
* Returns all tags for the current scenario and feature. | ||
* | ||
* @return string[] | ||
*/ | ||
protected function getTags() | ||
{ | ||
$featureTags = $this->getFeature()->getTags(); | ||
$scenarioTags = $this->getScenario()->getTags(); | ||
return array_unique(array_merge($featureTags, $scenarioTags)); | ||
} | ||
|
||
/** | ||
* Checks whether the current scenario or feature has the given tag. | ||
* | ||
* @param string $tag | ||
* | ||
* @return bool | ||
*/ | ||
protected function hasTag($tag) | ||
{ | ||
return in_array($tag, $this->getTags()); | ||
} | ||
} |