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 features by their paths.
19 * @author Konstantin Kudryashov <ever.zet@gmail.com>
21 class PathsFilter extends SimpleFilter
23 protected $filterPaths = array();
28 * @param string[] $paths List of approved paths
30 public function __construct(array $paths)
32 $this->filterPaths = array_map(
33 function ($realpath) {
34 return rtrim($realpath, DIRECTORY_SEPARATOR) .
35 (is_dir($realpath) ? DIRECTORY_SEPARATOR : '');
38 array_map('realpath', $paths)
44 * Checks if Feature matches specified filter.
46 * @param FeatureNode $feature Feature instance
50 public function isFeatureMatch(FeatureNode $feature)
52 foreach ($this->filterPaths as $path) {
53 if (0 === strpos(realpath($feature->getFile()), $path)) {
62 * Checks if scenario or outline matches specified filter.
64 * @param ScenarioInterface $scenario Scenario or Outline node instance
66 * @return false This filter is designed to work only with features
68 public function isScenarioMatch(ScenarioInterface $scenario)