4 * This file is part of the Behat Gherkin.
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\Gherkin\Filter;
13 use Behat\Gherkin\Node\FeatureNode;
14 use Behat\Gherkin\Node\ScenarioInterface;
17 * Filters scenarios by feature/scenario name.
19 * @author Konstantin Kudryashov <ever.zet@gmail.com>
21 class NameFilter extends SimpleFilter
23 protected $filterString;
28 * @param string $filterString Name filter string
30 public function __construct($filterString)
32 $this->filterString = trim($filterString);
36 * Checks if Feature matches specified filter.
38 * @param FeatureNode $feature Feature instance
42 public function isFeatureMatch(FeatureNode $feature)
44 if ('/' === $this->filterString[0]) {
45 return 1 === preg_match($this->filterString, $feature->getTitle());
48 return false !== mb_strpos($feature->getTitle(), $this->filterString, 0, 'utf8');
52 * Checks if scenario or outline matches specified filter.
54 * @param ScenarioInterface $scenario Scenario or Outline node instance
58 public function isScenarioMatch(ScenarioInterface $scenario)
60 if ('/' === $this->filterString[0] && 1 === preg_match($this->filterString, $scenario->getTitle())) {
62 } elseif (false !== mb_strpos($scenario->getTitle(), $this->filterString, 0, 'utf8')) {