From 637846ad220f3522dd006b464f7a8828a6bd5203 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] Enhancement: Allow specifying duration as value for --order-by option via CLI --- src/TextUI/Command.php | 5 +++ src/TextUI/Help.php | 2 +- .../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 + .../order-by-duration-via-cli.phpt | 34 +++++++++++++++++++ 7 files changed, 71 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/order-by-duration-via-cli.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/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/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..3f39049a7b9 --- /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/execution-order/_files/TestWithDifferentDurations.php +--FILE-- +