diff --git a/src/Framework/TestResult.php b/src/Framework/TestResult.php index dc31d748db7..f594c5a9b4a 100644 --- a/src/Framework/TestResult.php +++ b/src/Framework/TestResult.php @@ -177,12 +177,12 @@ class TestResult implements Countable /** * @var bool */ - private $stopOnDefect = false; + protected $lastTestFailed = false; /** * @var bool */ - protected $lastTestFailed = false; + private $stopOnDefect = false; /** * @var bool diff --git a/src/Runner/ResultCacheExtension.php b/src/Runner/ResultCacheExtension.php index cf3359565cd..221bd50cd19 100644 --- a/src/Runner/ResultCacheExtension.php +++ b/src/Runner/ResultCacheExtension.php @@ -29,12 +29,14 @@ public function flush(): void public function executeAfterSuccessfulTest(string $test, float $time): void { $testName = $this->getTestName($test); + $this->cache->setTime($testName, \round($time, 3)); } public function executeAfterIncompleteTest(string $test, string $message, float $time): void { $testName = $this->getTestName($test); + $this->cache->setTime($testName, \round($time, 3)); $this->cache->setState($testName, BaseTestRunner::STATUS_INCOMPLETE); } @@ -42,6 +44,7 @@ public function executeAfterIncompleteTest(string $test, string $message, float public function executeAfterRiskyTest(string $test, string $message, float $time): void { $testName = $this->getTestName($test); + $this->cache->setTime($testName, \round($time, 3)); $this->cache->setState($testName, BaseTestRunner::STATUS_RISKY); } @@ -49,6 +52,7 @@ public function executeAfterRiskyTest(string $test, string $message, float $time public function executeAfterSkippedTest(string $test, string $message, float $time): void { $testName = $this->getTestName($test); + $this->cache->setTime($testName, \round($time, 3)); $this->cache->setState($testName, BaseTestRunner::STATUS_SKIPPED); } @@ -56,6 +60,7 @@ public function executeAfterSkippedTest(string $test, string $message, float $ti public function executeAfterTestError(string $test, string $message, float $time): void { $testName = $this->getTestName($test); + $this->cache->setTime($testName, \round($time, 3)); $this->cache->setState($testName, BaseTestRunner::STATUS_ERROR); } @@ -63,6 +68,7 @@ public function executeAfterTestError(string $test, string $message, float $time public function executeAfterTestFailure(string $test, string $message, float $time): void { $testName = $this->getTestName($test); + $this->cache->setTime($testName, \round($time, 3)); $this->cache->setState($testName, BaseTestRunner::STATUS_FAILURE); } @@ -70,6 +76,7 @@ public function executeAfterTestFailure(string $test, string $message, float $ti public function executeAfterTestWarning(string $test, string $message, float $time): void { $testName = $this->getTestName($test); + $this->cache->setTime($testName, \round($time, 3)); $this->cache->setState($testName, BaseTestRunner::STATUS_WARNING); } diff --git a/src/Runner/TestSuiteSorter.php b/src/Runner/TestSuiteSorter.php index 9233a3f1431..13f1d802b45 100644 --- a/src/Runner/TestSuiteSorter.php +++ b/src/Runner/TestSuiteSorter.php @@ -89,6 +89,7 @@ public function reorderTestsInSuite(Test $suite, int $order, bool $resolveDepend if ($orderDefects === self::ORDER_DEFECTS_FIRST) { $this->addSuiteToDefectSortOrder($suite); } + $this->sort($suite, $order, $resolveDependencies, $orderDefects); } } @@ -130,9 +131,13 @@ private function addSuiteToDefectSortOrder(TestSuite $suite): void private function suiteOnlyContainsTests(TestSuite $suite): bool { - return \array_reduce($suite->tests(), function ($carry, $test) { - return $carry && ($test instanceof TestCase || $test instanceof DataProviderTestSuite); - }, true); + return \array_reduce( + $suite->tests(), + function ($carry, $test) { + return $carry && ($test instanceof TestCase || $test instanceof DataProviderTestSuite); + }, + true + ); } private function reverse(array $tests): array @@ -149,9 +154,12 @@ private function randomize(array $tests): array private function sortDefectsFirst(array $tests): array { - \usort($tests, function ($left, $right) { - return $this->cmpDefectPriorityAndTime($left, $right); - }); + \usort( + $tests, + function ($left, $right) { + return $this->cmpDefectPriorityAndTime($left, $right); + } + ); return $tests; } @@ -202,9 +210,12 @@ private function resolveDependencies(array $tests): array $i = 0; do { - $todoNames = \array_map(function ($test) { - return $this->getNormalizedTestName($test); - }, $tests); + $todoNames = \array_map( + function ($test) { + return $this->getNormalizedTestName($test); + }, + $tests + ); if (!$tests[$i]->hasDependencies() || empty(\array_intersect($this->getNormalizedDependencyNames($tests[$i]), $todoNames))) { $newTestOrder = \array_merge($newTestOrder, \array_splice($tests, $i, 1)); @@ -244,11 +255,12 @@ private function getNormalizedDependencyNames($test): array $testClass = \get_class($test); } - $names = \array_map(function ($name) use ($testClass) { - return \strpos($name, '::') === false - ? $testClass . '::' . $name - : $name; - }, $test->getDependencies()); + $names = \array_map( + function ($name) use ($testClass) { + return \strpos($name, '::') === false ? $testClass . '::' . $name : $name; + }, + $test->getDependencies() + ); return $names; } diff --git a/src/TextUI/Command.php b/src/TextUI/Command.php index 37be2f2b465..737a483a90d 100644 --- a/src/TextUI/Command.php +++ b/src/TextUI/Command.php @@ -1330,22 +1330,27 @@ private function handleOrderByOption(string $value): void $this->arguments['resolveDependencies'] = false; break; + case 'reverse': $this->arguments['executionOrder'] = TestSuiteSorter::ORDER_REVERSED; break; + case 'random': $this->arguments['executionOrder'] = TestSuiteSorter::ORDER_RANDOMIZED; break; + case 'defects': $this->arguments['executionOrderDefects'] = TestSuiteSorter::ORDER_DEFECTS_FIRST; break; + case 'depends': $this->arguments['resolveDependencies'] = true; break; + default: $this->exitWithErrorMessage("unrecognized --order-by option: $order"); } diff --git a/src/TextUI/TestRunner.php b/src/TextUI/TestRunner.php index 92238b0522f..b96a16e0cb5 100644 --- a/src/TextUI/TestRunner.php +++ b/src/TextUI/TestRunner.php @@ -183,6 +183,7 @@ public function doRun(Test $suite, array $arguments = [], bool $exit = true): Te } else { $cache = new TestResultCache; } + $this->extensions[] = new ResultCacheExtension($cache); } @@ -190,7 +191,9 @@ public function doRun(Test $suite, array $arguments = [], bool $exit = true): Te if (!isset($cache)) { $cache = new NullTestResultCache; } + $cache->load(); + $sorter = new TestSuiteSorter($cache); $sorter->reorderTestsInSuite($suite, $arguments['executionOrder'], $arguments['resolveDependencies'], $arguments['executionOrderDefects']);