Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Testwork / Ordering / Orderer / RandomOrderer.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\Testwork\Ordering\Orderer;
12
13 use Behat\Testwork\Specification\SpecificationArrayIterator;
14
15 /**
16  * Prioritises Suites and Features into random order
17  *
18  * @author Ciaran McNulty <mail@ciaranmcnulty.com>
19  */
20 final class RandomOrderer implements Orderer
21 {
22     /**
23      * @param SpecificationIterator[] $scenarioIterators
24      * @return SpecificationIterator[]
25      */
26     public function order(array $scenarioIterators)
27     {
28         $orderedFeatures = $this->orderFeatures($scenarioIterators);
29         shuffle($orderedFeatures);
30
31         return $orderedFeatures;
32     }
33
34     /**
35      * @param array $scenarioIterators
36      * @return array
37      */
38     private function orderFeatures(array $scenarioIterators)
39     {
40         $orderedSuites = array();
41
42         foreach ($scenarioIterators as $scenarioIterator) {
43             $orderedSpecifications = iterator_to_array($scenarioIterator);
44             shuffle($orderedSpecifications);
45             $orderedSuites[] = new SpecificationArrayIterator(
46                 $scenarioIterator->getSuite(),
47                 $orderedSpecifications
48             );
49         }
50
51         return $orderedSuites;
52     }
53
54     /**
55      * @return string
56      */
57     public function getName()
58     {
59         return 'random';
60     }
61 }