Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Hook / Call / RuntimeStepHook.php
1 <?php
2
3 /*
4  * This file is part of the Behat.
5  * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 namespace Behat\Behat\Hook\Call;
12
13 use Behat\Behat\Hook\Scope\StepScope;
14 use Behat\Gherkin\Filter\NameFilter;
15 use Behat\Gherkin\Node\StepNode;
16 use Behat\Testwork\Hook\Call\RuntimeFilterableHook;
17 use Behat\Testwork\Hook\Scope\HookScope;
18
19 /**
20  * Represents a step hook.
21  *
22  * @author Konstantin Kudryashov <ever.zet@gmail.com>
23  */
24 abstract class RuntimeStepHook extends RuntimeFilterableHook
25 {
26     /**
27      * {@inheritdoc}
28      */
29     public function filterMatches(HookScope $scope)
30     {
31         if (!$scope instanceof StepScope) {
32             return false;
33         }
34
35         if (null === ($filterString = $this->getFilterString())) {
36             return true;
37         }
38
39         if (!empty($filterString)) {
40             $filter = new NameFilter($filterString);
41
42             if ($filter->isFeatureMatch($scope->getFeature())) {
43                 return true;
44             }
45
46             return $this->isStepMatch($scope->getStep(), $filterString);
47         }
48
49         return false;
50     }
51
52     /**
53      * Checks if Feature matches specified filter.
54      *
55      * @param StepNode $step
56      * @param string   $filterString
57      *
58      * @return Boolean
59      */
60     private function isStepMatch(StepNode $step, $filterString)
61     {
62         if ('/' === $filterString[0]) {
63             return 1 === preg_match($filterString, $step->getText());
64         }
65
66         return false !== mb_strpos($step->getText(), $filterString, 0, 'utf8');
67     }
68 }