4 * This file is part of the Behat.
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\Testwork\Ordering;
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;
22 * Exercise that is ordered according to a specified algorithm
24 * @author Ciaran McNulty <mail@ciaranmcnulty.com>
26 final class OrderedExercise implements Exercise
34 * @var SpecificationIterator[]
39 * @var SpecificationIterator[]
46 private $decoratedExercise;
49 * @param Exercise $decoratedExercise
51 public function __construct(Exercise $decoratedExercise)
53 $this->orderer = new NoopOrderer();
54 $this->decoratedExercise = $decoratedExercise;
58 * Sets up exercise for a test.
60 * @param SpecificationIterator[] $iterators
61 * @param Boolean $skip
65 public function setUp(array $iterators, $skip)
67 return $this->decoratedExercise->setUp($this->order($iterators), $skip);
71 * Tests suites specifications.
73 * @param SpecificationIterator[] $iterators
74 * @param Boolean $skip
78 public function test(array $iterators, $skip)
80 return $this->decoratedExercise->test($this->order($iterators), $skip);
84 * Tears down exercise after a test.
86 * @param SpecificationIterator[] $iterators
87 * @param Boolean $skip
88 * @param TestResult $result
92 public function tearDown(array $iterators, $skip, TestResult $result)
94 return $this->decoratedExercise->tearDown($this->order($iterators), $skip, $result);
98 * Replace the algorithm being used for prioritisation
100 * @param Orderer $orderer
102 public function setOrderer(Orderer $orderer)
104 $this->orderer = $orderer;
108 * @param SpecificationIterator[] $iterators
109 * @return SpecificationIterator[]
111 private function order(array $iterators)
113 if (!$this->ordered || $this->unordered != $iterators) {
114 $this->unordered = $iterators;
115 $this->ordered = $this->orderer->order($iterators);
118 return $this->ordered;