From 84f0bed2a723dc056e412475fd8f0a39275505f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sun, 5 May 2019 09:36:22 +0200 Subject: [PATCH] Fix: Handle duration as order-by option value on CLI --- src/TextUI/Command.php | 7 +++- .../TestWithDifferentDurations.php | 28 +++++++++++++++ ...ifferentDurations.phpunit.result.cache.txt | 1 + .../order-by-duration-via-cli.phpt | 34 +++++++++++++++++++ tests/end-to-end/help.phpt | 2 +- tests/end-to-end/help2.phpt | 2 +- 6 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 tests/end-to-end/_files/execution-order/TestWithDifferentDurations.php create mode 100644 tests/end-to-end/_files/execution-order/TestWithDifferentDurations.phpunit.result.cache.txt create mode 100644 tests/end-to-end/execution-order/order-by-duration-via-cli.phpt diff --git a/src/TextUI/Command.php b/src/TextUI/Command.php index 73341f46fe1..d6bcf5590ed 100644 --- a/src/TextUI/Command.php +++ b/src/TextUI/Command.php @@ -1158,7 +1158,7 @@ protected function showHelp(): void --printer TestListener implementation to use --resolve-dependencies Resolve dependencies between tests - --order-by= Run tests in order: default|defects|depends|random|reverse + --order-by= Run tests in order: default|defects|depends|duration|random|reverse --random-order-seed= Use a specific random seed for random order --cache-result Write run result to cache to enable ordering tests defects-first @@ -1356,6 +1356,11 @@ private function handleOrderByOption(string $value): void break; + case 'duration': + $this->arguments['executionOrder'] = TestSuiteSorter::ORDER_DURATION; + + break; + case 'random': $this->arguments['executionOrder'] = TestSuiteSorter::ORDER_RANDOMIZED; diff --git a/tests/end-to-end/_files/execution-order/TestWithDifferentDurations.php b/tests/end-to-end/_files/execution-order/TestWithDifferentDurations.php new file mode 100644 index 00000000000..102620c1833 --- /dev/null +++ b/tests/end-to-end/_files/execution-order/TestWithDifferentDurations.php @@ -0,0 +1,28 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +use PHPUnit\Framework\TestCase; + +final class TestWithDifferentDurations extends TestCase +{ + public function testOne(): void + { + $this->assertTrue(true); + } + + public function testTwo(): void + { + $this->assertTrue(true); + } + + public function testThree(): void + { + $this->assertTrue(true); + } +} diff --git a/tests/end-to-end/_files/execution-order/TestWithDifferentDurations.phpunit.result.cache.txt b/tests/end-to-end/_files/execution-order/TestWithDifferentDurations.phpunit.result.cache.txt new file mode 100644 index 00000000000..732de2bb136 --- /dev/null +++ b/tests/end-to-end/_files/execution-order/TestWithDifferentDurations.phpunit.result.cache.txt @@ -0,0 +1 @@ +C:30:"PHPUnit\Runner\TestResultCache":199:{a:2:{s:7:"defects";a:0:{}s:5:"times";a:3:{s:35:"TestWithDifferentDurations::testOne";d:1.000;s:35:"TestWithDifferentDurations::testTwo";d:0.500;s:37:"TestWithDifferentDurations::testThree";d:1.500;}}} diff --git a/tests/end-to-end/execution-order/order-by-duration-via-cli.phpt b/tests/end-to-end/execution-order/order-by-duration-via-cli.phpt new file mode 100644 index 00000000000..88829c830b9 --- /dev/null +++ b/tests/end-to-end/execution-order/order-by-duration-via-cli.phpt @@ -0,0 +1,34 @@ +--TEST-- +phpunit --order-by=duration ./tests/end-to-end/_files/execution-order/TestWithDifferentDurations.php +--FILE-- + TestListener implementation to use --resolve-dependencies Resolve dependencies between tests - --order-by= Run tests in order: default|defects|depends|random|reverse + --order-by= Run tests in order: default|defects|depends|duration|random|reverse --random-order-seed= Use a specific random seed for random order --cache-result Write run result to cache to enable ordering tests defects-first diff --git a/tests/end-to-end/help2.phpt b/tests/end-to-end/help2.phpt index 7ff3575c0c0..996da580ee1 100644 --- a/tests/end-to-end/help2.phpt +++ b/tests/end-to-end/help2.phpt @@ -89,7 +89,7 @@ Test Execution Options: --printer TestListener implementation to use --resolve-dependencies Resolve dependencies between tests - --order-by= Run tests in order: default|defects|depends|random|reverse + --order-by= Run tests in order: default|defects|depends|duration|random|reverse --random-order-seed= Use a specific random seed for random order --cache-result Write run result to cache to enable ordering tests defects-first