From 7f6fa25f788e689bf1d6b7eb949d9c32fba97f55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Mon, 6 May 2019 08:15:39 +0200 Subject: [PATCH 1/3] Enhancement: Allow using duration as option value for execution order --- src/TextUI/Command.php | 5 +++ src/TextUI/Help.php | 2 +- src/Util/Configuration.php | 4 +++ .../cli/_files/output-cli-help-color.txt | 2 +- .../cli/_files/output-cli-usage.txt | 2 +- .../_files/TestWithDifferentDurations.php | 28 ++++++++++++++++ ...ifferentDurations.phpunit.result.cache.txt | 1 + .../_files/order-by-duration.phpunit.xml | 11 +++++++ .../order-by-duration-via-cli.phpt | 33 +++++++++++++++++++ .../order-by-duration-via-phpunit-xml.phpt | 33 +++++++++++++++++++ 10 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 tests/end-to-end/execution-order/_files/TestWithDifferentDurations.php create mode 100644 tests/end-to-end/execution-order/_files/TestWithDifferentDurations.phpunit.result.cache.txt create mode 100644 tests/end-to-end/execution-order/_files/order-by-duration.phpunit.xml create mode 100644 tests/end-to-end/execution-order/order-by-duration-via-cli.phpt create mode 100644 tests/end-to-end/execution-order/order-by-duration-via-phpunit-xml.phpt diff --git a/src/TextUI/Command.php b/src/TextUI/Command.php index a25e9f54b55..4a6cfccac20 100644 --- a/src/TextUI/Command.php +++ b/src/TextUI/Command.php @@ -1282,6 +1282,11 @@ private function handleOrderByOption(string $value): void break; + case 'duration': + $this->arguments['executionOrder'] = TestSuiteSorter::ORDER_DURATION; + + break; + default: $this->exitWithErrorMessage("unrecognized --order-by option: $order"); } diff --git a/src/TextUI/Help.php b/src/TextUI/Help.php index 869043d8ce7..62a4689e1f8 100644 --- a/src/TextUI/Help.php +++ b/src/TextUI/Help.php @@ -100,7 +100,7 @@ final class Help ['arg' => '--printer ', 'desc' => 'TestListener implementation to use'], ['spacer' => ''], - ['arg' => '--order-by=', 'desc' => 'Run tests in order: default|reverse|random|defects|no-depends'], + ['arg' => '--order-by=', 'desc' => 'Run tests in order: default|reverse|random|defects|no-depends|duration'], ['arg' => '--random-order-seed=', 'desc' => 'Use a specific random seed for random order'], ['arg' => '--cache-result', 'desc' => 'Write test results to cache file'], ['arg' => '--do-not-cache-result', 'desc' => 'Do not write test results to cache file'], diff --git a/src/Util/Configuration.php b/src/Util/Configuration.php index b79916c843d..6b4db4faec9 100644 --- a/src/Util/Configuration.php +++ b/src/Util/Configuration.php @@ -853,6 +853,10 @@ public function getPHPUnitConfiguration(): array case 'no-depends': $result['resolveDependencies'] = false; + break; + case 'duration': + $result['executionOrder'] = TestSuiteSorter::ORDER_DURATION; + break; } } diff --git a/tests/end-to-end/cli/_files/output-cli-help-color.txt b/tests/end-to-end/cli/_files/output-cli-help-color.txt index ab5dbec3f43..b1e08da09ff 100644 --- a/tests/end-to-end/cli/_files/output-cli-help-color.txt +++ b/tests/end-to-end/cli/_files/output-cli-help-color.txt @@ -99,7 +99,7 @@ --printer   TestListener implementation to use --order-by=  Run tests in order: - default|reverse|random|defects|no-depends + default|reverse|random|defects|no-depends|duration --random-order-seed=  Use a specific random seed for random order --cache-result  Write test results to cache file diff --git a/tests/end-to-end/cli/_files/output-cli-usage.txt b/tests/end-to-end/cli/_files/output-cli-usage.txt index 5134d0dcee3..7f6ba374681 100644 --- a/tests/end-to-end/cli/_files/output-cli-usage.txt +++ b/tests/end-to-end/cli/_files/output-cli-usage.txt @@ -77,7 +77,7 @@ Test Execution Options: --testdox-exclude-group Exclude tests from the specified group(s) --printer TestListener implementation to use - --order-by= Run tests in order: default|reverse|random|defects|no-depends + --order-by= Run tests in order: default|reverse|random|defects|no-depends|duration --random-order-seed= Use a specific random seed for random order --cache-result Write test results to cache file --do-not-cache-result Do not write test results to cache file diff --git a/tests/end-to-end/execution-order/_files/TestWithDifferentDurations.php b/tests/end-to-end/execution-order/_files/TestWithDifferentDurations.php new file mode 100644 index 00000000000..8d0b6f381a7 --- /dev/null +++ b/tests/end-to-end/execution-order/_files/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/execution-order/_files/TestWithDifferentDurations.phpunit.result.cache.txt b/tests/end-to-end/execution-order/_files/TestWithDifferentDurations.phpunit.result.cache.txt new file mode 100644 index 00000000000..3a14002b065 --- /dev/null +++ b/tests/end-to-end/execution-order/_files/TestWithDifferentDurations.phpunit.result.cache.txt @@ -0,0 +1 @@ +C:37:"PHPUnit\Runner\DefaultTestResultCache":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/_files/order-by-duration.phpunit.xml b/tests/end-to-end/execution-order/_files/order-by-duration.phpunit.xml new file mode 100644 index 00000000000..2ef82a66223 --- /dev/null +++ b/tests/end-to-end/execution-order/_files/order-by-duration.phpunit.xml @@ -0,0 +1,11 @@ + + + + ./TestWithDifferentDurations.php + + + 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..e87094847a3 --- /dev/null +++ b/tests/end-to-end/execution-order/order-by-duration-via-cli.phpt @@ -0,0 +1,33 @@ +--TEST-- +phpunit --order-by=duration ./tests/end-to-end/execution-order/_files/TestWithDifferentDurations.php +--FILE-- + Date: Mon, 6 May 2019 09:07:03 +0200 Subject: [PATCH 2/3] Enhancement: Sort option values --- phpunit.xsd | 10 +++++----- src/TextUI/Help.php | 2 +- tests/end-to-end/cli/_files/output-cli-help-color.txt | 2 +- tests/end-to-end/cli/_files/output-cli-usage.txt | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/phpunit.xsd b/phpunit.xsd index 6eba998282c..2a32987971e 100644 --- a/phpunit.xsd +++ b/phpunit.xsd @@ -176,19 +176,19 @@ - - - + - + + - + + diff --git a/src/TextUI/Help.php b/src/TextUI/Help.php index 62a4689e1f8..ce0fd3af235 100644 --- a/src/TextUI/Help.php +++ b/src/TextUI/Help.php @@ -100,7 +100,7 @@ final class Help ['arg' => '--printer ', 'desc' => 'TestListener implementation to use'], ['spacer' => ''], - ['arg' => '--order-by=', 'desc' => 'Run tests in order: default|reverse|random|defects|no-depends|duration'], + ['arg' => '--order-by=', 'desc' => 'Run tests in order: default|defects|duration|no-depends|random|reverse'], ['arg' => '--random-order-seed=', 'desc' => 'Use a specific random seed for random order'], ['arg' => '--cache-result', 'desc' => 'Write test results to cache file'], ['arg' => '--do-not-cache-result', 'desc' => 'Do not write test results to cache file'], diff --git a/tests/end-to-end/cli/_files/output-cli-help-color.txt b/tests/end-to-end/cli/_files/output-cli-help-color.txt index b1e08da09ff..a889abbb3c3 100644 --- a/tests/end-to-end/cli/_files/output-cli-help-color.txt +++ b/tests/end-to-end/cli/_files/output-cli-help-color.txt @@ -99,7 +99,7 @@ --printer   TestListener implementation to use --order-by=  Run tests in order: - default|reverse|random|defects|no-depends|duration + default|defects|duration|no-depends|random|reverse --random-order-seed=  Use a specific random seed for random order --cache-result  Write test results to cache file diff --git a/tests/end-to-end/cli/_files/output-cli-usage.txt b/tests/end-to-end/cli/_files/output-cli-usage.txt index 7f6ba374681..ce9ae1eea13 100644 --- a/tests/end-to-end/cli/_files/output-cli-usage.txt +++ b/tests/end-to-end/cli/_files/output-cli-usage.txt @@ -77,7 +77,7 @@ Test Execution Options: --testdox-exclude-group Exclude tests from the specified group(s) --printer TestListener implementation to use - --order-by= Run tests in order: default|reverse|random|defects|no-depends|duration + --order-by= Run tests in order: default|defects|duration|no-depends|random|reverse --random-order-seed= Use a specific random seed for random order --cache-result Write test results to cache file --do-not-cache-result Do not write test results to cache file From 45d457160e128948f1b640a2194f8821ef52546f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Mon, 6 May 2019 09:10:34 +0200 Subject: [PATCH 3/3] Enhancement: Sort cases --- src/TextUI/Command.php | 24 ++++++++++++------------ src/Util/Configuration.php | 24 +++++++++++++++--------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/TextUI/Command.php b/src/TextUI/Command.php index 4a6cfccac20..b987d9562a9 100644 --- a/src/TextUI/Command.php +++ b/src/TextUI/Command.php @@ -1257,16 +1257,6 @@ private function handleOrderByOption(string $value): void 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; @@ -1277,13 +1267,23 @@ private function handleOrderByOption(string $value): void break; + case 'duration': + $this->arguments['executionOrder'] = TestSuiteSorter::ORDER_DURATION; + + break; + case 'no-depends': $this->arguments['resolveDependencies'] = false; break; - case 'duration': - $this->arguments['executionOrder'] = TestSuiteSorter::ORDER_DURATION; + case 'random': + $this->arguments['executionOrder'] = TestSuiteSorter::ORDER_RANDOMIZED; + + break; + + case 'reverse': + $this->arguments['executionOrder'] = TestSuiteSorter::ORDER_REVERSED; break; diff --git a/src/Util/Configuration.php b/src/Util/Configuration.php index 6b4db4faec9..3db2a5b85f1 100644 --- a/src/Util/Configuration.php +++ b/src/Util/Configuration.php @@ -834,28 +834,34 @@ public function getPHPUnitConfiguration(): array $result['resolveDependencies'] = false; break; - case 'reverse': - $result['executionOrder'] = TestSuiteSorter::ORDER_REVERSED; - - break; - case 'random': - $result['executionOrder'] = TestSuiteSorter::ORDER_RANDOMIZED; - break; case 'defects': $result['executionOrderDefects'] = TestSuiteSorter::ORDER_DEFECTS_FIRST; break; + case 'depends': $result['resolveDependencies'] = true; break; + + case 'duration': + $result['executionOrder'] = TestSuiteSorter::ORDER_DURATION; + + break; + case 'no-depends': $result['resolveDependencies'] = false; break; - case 'duration': - $result['executionOrder'] = TestSuiteSorter::ORDER_DURATION; + + case 'random': + $result['executionOrder'] = TestSuiteSorter::ORDER_RANDOMIZED; + + break; + + case 'reverse': + $result['executionOrder'] = TestSuiteSorter::ORDER_REVERSED; break; }