Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Gherkin / Specification / Locator / FilesystemRerunScenariosListLocator.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\Gherkin\Specification\Locator;
12
13 use Behat\Behat\Gherkin\Specification\LazyFeatureIterator;
14 use Behat\Gherkin\Gherkin;
15 use Behat\Testwork\Specification\Locator\SpecificationLocator;
16 use Behat\Testwork\Specification\NoSpecificationsIterator;
17 use Behat\Testwork\Suite\Suite;
18
19 /**
20  * Loads gherkin features using a file with the list of scenarios.
21  *
22  * @author Konstantin Kudryashov <ever.zet@gmail.com>
23  */
24 final class FilesystemRerunScenariosListLocator implements SpecificationLocator
25 {
26     /**
27      * @var Gherkin
28      */
29     private $gherkin;
30
31     /**
32      * Initializes locator.
33      *
34      * @param Gherkin $gherkin
35      */
36     public function __construct(Gherkin $gherkin)
37     {
38         $this->gherkin = $gherkin;
39     }
40
41     /**
42      * {@inheritdoc}
43      */
44     public function getLocatorExamples()
45     {
46         return array();
47     }
48
49     /**
50      * {@inheritdoc}
51      */
52     public function locateSpecifications(Suite $suite, $locator)
53     {
54         if (!is_file($locator) || 'rerun' !== pathinfo($locator, PATHINFO_EXTENSION)) {
55             return new NoSpecificationsIterator($suite);
56         }
57
58         $scenarios = json_decode(trim(file_get_contents($locator)), true);
59         if (empty($scenarios) || empty($scenarios[$suite->getName()])) {
60             return new NoSpecificationsIterator($suite);
61         }
62
63         return new LazyFeatureIterator($suite, $this->gherkin, $scenarios[$suite->getName()]);
64     }
65 }