Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Testwork / Specification / SpecificationFinder.php
1 <?php
2
3 /*
4  * This file is part of the Behat Testwork.
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\Testwork\Specification;
12
13 use Behat\Testwork\Specification\Locator\SpecificationLocator;
14 use Behat\Testwork\Suite\Suite;
15
16 /**
17  * Finds test specifications for provided suites using registered locators.
18  *
19  * @author Konstantin Kudryashov <ever.zet@gmail.com>
20  */
21 final class SpecificationFinder
22 {
23     /**
24      * @var SpecificationLocator[]
25      */
26     private $specificationLocators = array();
27
28     /**
29      * Registers specification locator.
30      *
31      * @param SpecificationLocator $locator
32      */
33     public function registerSpecificationLocator(SpecificationLocator $locator)
34     {
35         $this->specificationLocators[] = $locator;
36     }
37
38     /**
39      * Returns array of strings representing examples of supported specification locators.
40      *
41      * @return string[]
42      */
43     public function getExampleLocators()
44     {
45         $examples = array();
46         foreach ($this->specificationLocators as $locator) {
47             $examples = array_merge($examples, $locator->getLocatorExamples());
48         }
49
50         return $examples;
51     }
52
53     /**
54      * Finds all specifications for all provided suites matching provided locator and wraps them into a spec iterator.
55      *
56      * @param Suite[]     $suites
57      * @param null|string $locator
58      *
59      * @return SpecificationIterator[]
60      */
61     public function findSuitesSpecifications(array $suites, $locator = null)
62     {
63         $iterators = array();
64         foreach ($suites as $suite) {
65             $iterators = array_merge($iterators, $this->findSuiteSpecifications($suite, $locator));
66         }
67
68         return $iterators;
69     }
70
71     /**
72      * Creates suite specification iterator for provided locator.
73      *
74      * @param Suite       $suite
75      * @param null|string $locator
76      *
77      * @return SpecificationIterator[]
78      */
79     private function findSuiteSpecifications(Suite $suite, $locator = null)
80     {
81         $iterators = array();
82         foreach ($this->specificationLocators as $specificationLocator) {
83             $iterators[] = $specificationLocator->locateSpecifications($suite, $locator);
84         }
85
86         return $iterators;
87     }
88 }