Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Testwork / Ordering / OrderedExercise.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;
12
13 use Behat\Testwork\Ordering\Orderer\NoopOrderer;
14 use Behat\Testwork\Ordering\Orderer\Orderer;
15 use Behat\Testwork\Specification\SpecificationIterator;
16 use Behat\Testwork\Tester\Exercise;
17 use Behat\Testwork\Tester\Result\TestResult;
18 use Behat\Testwork\Tester\Setup\Setup;
19 use Behat\Testwork\Tester\Setup\Teardown;
20
21 /**
22  * Exercise that is ordered according to a specified algorithm
23  *
24  * @author Ciaran McNulty <mail@ciaranmcnulty.com>
25  */
26 final class OrderedExercise implements Exercise
27 {
28     /**
29      * @var Orderer
30      */
31     private $orderer;
32
33     /**
34      * @var SpecificationIterator[]
35      */
36     private $unordered;
37
38     /**
39      * @var SpecificationIterator[]
40      */
41     private $ordered;
42
43     /**
44      * @var Exercise
45      */
46     private $decoratedExercise;
47
48     /**
49      * @param Exercise $decoratedExercise
50      */
51     public function __construct(Exercise $decoratedExercise)
52     {
53         $this->orderer = new NoopOrderer();
54         $this->decoratedExercise = $decoratedExercise;
55     }
56
57     /**
58      * Sets up exercise for a test.
59      *
60      * @param SpecificationIterator[] $iterators
61      * @param Boolean $skip
62      *
63      * @return Setup
64      */
65     public function setUp(array $iterators, $skip)
66     {
67         return $this->decoratedExercise->setUp($this->order($iterators), $skip);
68     }
69
70     /**
71      * Tests suites specifications.
72      *
73      * @param SpecificationIterator[] $iterators
74      * @param Boolean $skip
75      *
76      * @return TestResult
77      */
78     public function test(array $iterators, $skip)
79     {
80         return $this->decoratedExercise->test($this->order($iterators), $skip);
81     }
82
83     /**
84      * Tears down exercise after a test.
85      *
86      * @param SpecificationIterator[] $iterators
87      * @param Boolean $skip
88      * @param TestResult $result
89      *
90      * @return Teardown
91      */
92     public function tearDown(array $iterators, $skip, TestResult $result)
93     {
94         return $this->decoratedExercise->tearDown($this->order($iterators), $skip, $result);
95     }
96
97     /**
98      * Replace the algorithm being used for prioritisation
99      *
100      * @param Orderer $orderer
101      */
102     public function setOrderer(Orderer $orderer)
103     {
104         $this->orderer = $orderer;
105     }
106
107     /**
108      * @param SpecificationIterator[] $iterators
109      * @return SpecificationIterator[]
110      */
111     private function order(array $iterators)
112     {
113         if (!$this->ordered || $this->unordered != $iterators) {
114             $this->unordered = $iterators;
115             $this->ordered = $this->orderer->order($iterators);
116         }
117
118         return $this->ordered;
119     }
120 }