From 7bb396efd5c54c48d80c86410fca6323edeeab72 Mon Sep 17 00:00:00 2001 From: asoulard Date: Tue, 5 Apr 2022 13:58:45 +0200 Subject: [PATCH 1/4] WIZ-11443 Slice tests in handleArguments instead of run and remove TestRunner. --- src/Command.php | 14 ++++++++++++-- src/TestRunner.php | 24 ------------------------ 2 files changed, 12 insertions(+), 26 deletions(-) delete mode 100644 src/TestRunner.php diff --git a/src/Command.php b/src/Command.php index 2a27329..1ec6834 100644 --- a/src/Command.php +++ b/src/Command.php @@ -4,6 +4,8 @@ namespace Wizaplace\PHPUnit\Slicer; +use PHPUnit\Framework\TestSuite; + class Command extends \PHPUnit\TextUI\Command { public function __construct() @@ -51,8 +53,16 @@ protected function showHelp(): void EOT; } - protected function createRunner(): \PHPUnit\TextUI\TestRunner + protected function handleArguments(array $argv): void { - return new TestRunner($this->arguments['loader']); + parent::handleArguments($argv); + + if (isset($this->arguments['totalSlices'], $this->arguments['currentSlice'], $this->arguments['test']) + && $this->arguments['test'] instanceof TestSuite + ) { + $localArguments = $this->arguments; + + $this->arguments['test'] = TestSuiteSlicer::slice($this->arguments['test'], $localArguments); + } } } diff --git a/src/TestRunner.php b/src/TestRunner.php deleted file mode 100644 index 9b02064..0000000 --- a/src/TestRunner.php +++ /dev/null @@ -1,24 +0,0 @@ -handleConfiguration($localArguments); - - TestSuiteSlicer::slice($suite, $localArguments); - } - - return parent::doRun($suite, $arguments, $exit); - } -} From fb677a7d6f778c32c74611cf19ca7ed560822c8e Mon Sep 17 00:00:00 2001 From: asoulard Date: Tue, 5 Apr 2022 14:06:08 +0200 Subject: [PATCH 2/4] WIZ-11443 Remove unbreakable spaces in tests. --- tests/TestSuiteSlicerTest.php | 54 +++++++++++++++++------------------ tests/fixtures/ATest.php | 6 ++-- tests/fixtures/BTest.php | 10 +++---- tests/fixtures/CTest.php | 14 ++++----- 4 files changed, 42 insertions(+), 42 deletions(-) diff --git a/tests/TestSuiteSlicerTest.php b/tests/TestSuiteSlicerTest.php index aac23a4..3c70a1e 100644 --- a/tests/TestSuiteSlicerTest.php +++ b/tests/TestSuiteSlicerTest.php @@ -33,7 +33,7 @@ public static function tearDownAfterClass(): void self::$tested = null; } - public function test slice first half() + public function testSliceFirstHalf() { $suite = clone self::$tested; self::assertCount(19, $suite); @@ -52,20 +52,20 @@ public function test slice first half() }, $this->extractTestsInSuite($suite)); self::assertEquals([ - 'test A', - 'test B', - 'test C', - 'test D', - 'test E', - 'test F', - 'test G', - 'test H', - 'test I', - 'test J', + 'testA', + 'testB', + 'testC', + 'testD', + 'testE', + 'testF', + 'testG', + 'testH', + 'testI', + 'testJ', ], $testsNames); } - public function test slice second half() + public function testSliceSecondHalf() { $suite = clone self::$tested; self::assertCount(19, $suite); @@ -84,19 +84,19 @@ public function test slice second half() }, $this->extractTestsInSuite($suite)); self::assertEquals([ - 'test K', - 'test L', - 'test M with data set #0', - 'test M with data set #1', - 'test M with data set #2', - 'test M with data set #3', - 'test M with data set #4', - 'test N', - 'test O', + 'testK', + 'testL', + 'testM with data set #0', + 'testM with data set #1', + 'testM with data set #2', + 'testM with data set #3', + 'testM with data set #4', + 'testN', + 'testO', ], $testsNames); } - public function test slice last third() + public function testSliceLastThird() { $suite = clone self::$tested; self::assertCount(19, $suite); @@ -115,11 +115,11 @@ public function test slice last third() }, $this->extractTestsInSuite($suite)); self::assertEquals([ - 'test M with data set #2', - 'test M with data set #3', - 'test M with data set #4', - 'test N', - 'test O', + 'testM with data set #2', + 'testM with data set #3', + 'testM with data set #4', + 'testN', + 'testO', ], $testsNames); } diff --git a/tests/fixtures/ATest.php b/tests/fixtures/ATest.php index fa82ad1..6d86085 100644 --- a/tests/fixtures/ATest.php +++ b/tests/fixtures/ATest.php @@ -6,7 +6,7 @@ class ATest extends TestCase { - public function test A() { } - public function test B() { } - public function test C() { } + public function testA() { } + public function testB() { } + public function testC() { } } diff --git a/tests/fixtures/BTest.php b/tests/fixtures/BTest.php index ec76cfd..a0bfccf 100644 --- a/tests/fixtures/BTest.php +++ b/tests/fixtures/BTest.php @@ -6,9 +6,9 @@ class BTest extends TestCase { - public function test D() { } - public function test E() { } - public function test F() { } - public function test G() { } - public function test H() { } + public function testD() { } + public function testE() { } + public function testF() { } + public function testG() { } + public function testH() { } } diff --git a/tests/fixtures/CTest.php b/tests/fixtures/CTest.php index d40aff7..f14b274 100644 --- a/tests/fixtures/CTest.php +++ b/tests/fixtures/CTest.php @@ -6,15 +6,15 @@ class CTest extends TestCase { - public function test I() { } - public function test J() { } - public function test K() { } - public function test L() { } + public function testI() { } + public function testJ() { } + public function testK() { } + public function testL() { } /** * @dataProvider dataProvider */ - public function test M($a) { } + public function testM($a) { } public function dataProvider() { @@ -27,6 +27,6 @@ public function dataProvider() ]; } - public function test N() { } - public function test O() { } + public function testN() { } + public function testO() { } } From 6c43e6fc1df69756ff7ecb2dddf06111c1f3b94c Mon Sep 17 00:00:00 2001 From: asoulard Date: Tue, 5 Apr 2022 14:59:04 +0200 Subject: [PATCH 3/4] WIZ-11443 Fix slice must return the modified TestSuite object. --- src/TestSuiteSlicer.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/TestSuiteSlicer.php b/src/TestSuiteSlicer.php index 0a536d3..5c2dcf7 100644 --- a/src/TestSuiteSlicer.php +++ b/src/TestSuiteSlicer.php @@ -8,7 +8,7 @@ class TestSuiteSlicer { - public static function slice(TestSuite $suite, array $arguments) + public static function slice(TestSuite $suite, array $arguments): TestSuite { $tests = self::extractTestsInSuite($suite); @@ -34,6 +34,8 @@ public static function slice(TestSuite $suite, array $arguments) $offset+1, $lastTestId ); + + return $suite; } private static function extractTestsInSuite(TestSuite $suite) : array From 48e72fa0389f2f2b681a39179a9a6a012c87bca4 Mon Sep 17 00:00:00 2001 From: asoulard Date: Tue, 5 Apr 2022 15:04:16 +0200 Subject: [PATCH 4/4] WIZ-11443 Fix tests for slice return type. --- tests/TestSuiteSlicerTest.php | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/tests/TestSuiteSlicerTest.php b/tests/TestSuiteSlicerTest.php index 3c70a1e..d0cc1bd 100644 --- a/tests/TestSuiteSlicerTest.php +++ b/tests/TestSuiteSlicerTest.php @@ -33,6 +33,15 @@ public static function tearDownAfterClass(): void self::$tested = null; } + public function testSliceReturnsATestSuiteObject(): void + { + $suite = clone self::$tested; + + $modifiedSuite = TestSuiteSlicer::slice($suite, ['currentSlice' => 1, 'totalSlices' => 2]); + + self::assertInstanceOf(TestSuite::class, $modifiedSuite); + } + public function testSliceFirstHalf() { $suite = clone self::$tested; @@ -40,16 +49,16 @@ public function testSliceFirstHalf() ob_start(); - TestSuiteSlicer::slice($suite, ['currentSlice' => 1, 'totalSlices' => 2]); + $modifiedSuite = TestSuiteSlicer::slice($suite, ['currentSlice' => 1, 'totalSlices' => 2]); $output = ob_get_clean(); self::assertEquals("PHPUnit suite slicer, running slice 1/2 (10 tests: from #1 to #10)\n", $output); - self::assertCount(10, $suite); + self::assertCount(10, $modifiedSuite); $testsNames = array_map(function(TestCase $test) { return $test->getName(); - }, $this->extractTestsInSuite($suite)); + }, $this->extractTestsInSuite($modifiedSuite)); self::assertEquals([ 'testA', @@ -72,16 +81,16 @@ public function testSliceSecondHalf() ob_start(); - TestSuiteSlicer::slice($suite, ['currentSlice' => 2, 'totalSlices' => 2]); + $modifiedSuite = TestSuiteSlicer::slice($suite, ['currentSlice' => 2, 'totalSlices' => 2]); $output = ob_get_clean(); self::assertEquals("PHPUnit suite slicer, running slice 2/2 (9 tests: from #11 to #19)\n", $output); - self::assertCount(9, $suite); + self::assertCount(9, $modifiedSuite); $testsNames = array_map(function(TestCase $test) { return $test->getName(); - }, $this->extractTestsInSuite($suite)); + }, $this->extractTestsInSuite($modifiedSuite)); self::assertEquals([ 'testK', @@ -103,16 +112,16 @@ public function testSliceLastThird() ob_start(); - TestSuiteSlicer::slice($suite, ['currentSlice' => 3, 'totalSlices' => 3]); + $modifiedSuite = TestSuiteSlicer::slice($suite, ['currentSlice' => 3, 'totalSlices' => 3]); $output = ob_get_clean(); self::assertEquals("PHPUnit suite slicer, running slice 3/3 (5 tests: from #15 to #19)\n", $output); - self::assertCount(5, $suite); + self::assertCount(5, $modifiedSuite); $testsNames = array_map(function(TestCase $test) { return $test->getName(); - }, $this->extractTestsInSuite($suite)); + }, $this->extractTestsInSuite($modifiedSuite)); self::assertEquals([ 'testM with data set #2',