4 * This file is part of the Behat.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace Behat\Behat\Hook\Call;
13 use Behat\Behat\Hook\Scope\ScenarioScope;
14 use Behat\Gherkin\Filter\NameFilter;
15 use Behat\Gherkin\Filter\TagFilter;
16 use Behat\Gherkin\Node\FeatureNode;
17 use Behat\Gherkin\Node\ScenarioInterface;
18 use Behat\Testwork\Hook\Call\RuntimeFilterableHook;
19 use Behat\Testwork\Hook\Scope\HookScope;
22 * Represents a scenario hook.
24 * @author Konstantin Kudryashov <ever.zet@gmail.com>
26 abstract class RuntimeScenarioHook extends RuntimeFilterableHook
31 public function filterMatches(HookScope $scope)
33 if (!$scope instanceof ScenarioScope) {
37 if (null === ($filterString = $this->getFilterString())) {
41 return $this->isMatch($scope->getFeature(), $scope->getScenario(), $filterString);
45 * Checks if nodes match filter.
47 * @param FeatureNode $feature
48 * @param ScenarioInterface $scenario
49 * @param string $filterString
53 protected function isMatch(FeatureNode $feature, ScenarioInterface $scenario, $filterString)
55 if (false !== strpos($filterString, '@')) {
56 return $this->isMatchTagFilter($feature, $scenario, $filterString);
59 if (!empty($filterString)) {
60 return $this->isMatchNameFilter($scenario, $filterString);
67 * Checks if node match tag filter.
69 * @param FeatureNode $feature
70 * @param ScenarioInterface $scenario
71 * @param string $filterString
75 protected function isMatchTagFilter(FeatureNode $feature, ScenarioInterface $scenario, $filterString)
77 $filter = new TagFilter($filterString);
79 if ($filter->isFeatureMatch($feature)) {
83 return $filter->isScenarioMatch($feature, $scenario);
87 * Checks if scenario matches name filter.
89 * @param ScenarioInterface $scenario
90 * @param string $filterString
94 protected function isMatchNameFilter(ScenarioInterface $scenario, $filterString)
96 $filter = new NameFilter($filterString);
98 return $filter->isScenarioMatch($scenario);