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\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;
20 * Represents a step hook.
22 * @author Konstantin Kudryashov <ever.zet@gmail.com>
24 abstract class RuntimeStepHook extends RuntimeFilterableHook
29 public function filterMatches(HookScope $scope)
31 if (!$scope instanceof StepScope) {
35 if (null === ($filterString = $this->getFilterString())) {
39 if (!empty($filterString)) {
40 $filter = new NameFilter($filterString);
42 if ($filter->isFeatureMatch($scope->getFeature())) {
46 return $this->isStepMatch($scope->getStep(), $filterString);
53 * Checks if Feature matches specified filter.
55 * @param StepNode $step
56 * @param string $filterString
60 private function isStepMatch(StepNode $step, $filterString)
62 if ('/' === $filterString[0]) {
63 return 1 === preg_match($filterString, $step->getText());
66 return false !== mb_strpos($step->getText(), $filterString, 0, 'utf8');