From 8a29e08ea7de9b50c8c18f951eb302f5a42bbdd4 Mon Sep 17 00:00:00 2001 From: Hugo Casabella Date: Fri, 2 Oct 2020 12:07:18 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=8E=A8=20Improve=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 5 +- phpunit.xml.dist | 2 +- src/Command.php | 36 +++++++++++--- src/TestRunner.php | 24 ---------- tests/Fixtures/ATest.php | 14 ++++++ tests/Fixtures/BTest.php | 16 +++++++ tests/{fixtures => Fixtures}/CTest.php | 16 ++++--- tests/TestSuiteSlicerTest.php | 65 +++++++++++++------------- tests/fixtures/ATest.php | 12 ----- tests/fixtures/BTest.php | 14 ------ 10 files changed, 106 insertions(+), 98 deletions(-) delete mode 100644 src/TestRunner.php create mode 100644 tests/Fixtures/ATest.php create mode 100644 tests/Fixtures/BTest.php rename tests/{fixtures => Fixtures}/CTest.php (52%) delete mode 100644 tests/fixtures/ATest.php delete mode 100644 tests/fixtures/BTest.php diff --git a/composer.json b/composer.json index 8d2f684..4a8e4af 100644 --- a/composer.json +++ b/composer.json @@ -3,11 +3,12 @@ "license": "MIT", "require": { "php": "^7.1", - "phpunit/phpunit": "^7|^8" + "phpunit/phpunit": "^7|^8|^9" }, "autoload": { "psr-4": { - "Wizaplace\\PHPUnit\\Slicer\\": "src/" + "Wizaplace\\PHPUnit\\Slicer\\": "src/", + "Wizaplace\\PHPUnit\\Tests\\Slicer\\": "tests/" } }, "bin": [ diff --git a/phpunit.xml.dist b/phpunit.xml.dist index be81382..c957687 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -9,7 +9,7 @@ ./tests - ./tests/fixtures + ./tests/Fixtures diff --git a/src/Command.php b/src/Command.php index 2a27329..6b0059f 100644 --- a/src/Command.php +++ b/src/Command.php @@ -4,13 +4,42 @@ namespace Wizaplace\PHPUnit\Slicer; +use PHPUnit\Framework\TestSuite; + class Command extends \PHPUnit\TextUI\Command { public function __construct() { $this->longOptions['slices='] = 'slicesHandler'; + } + + public static function main(bool $exit = true): int + { + return (new static)->runSlicer($_SERVER['argv'], $exit); + } + + public function runSlicer(array $argv, bool $exit = true): int + { + $this->handleArguments($argv); + + $runner = $this->createRunner(); - // there is no parent construct + if ($this->arguments['test'] instanceof TestSuite) { + $suite = $this->arguments['test']; + } else { + $suite = $runner->getTest( + $this->arguments['test'], + $this->arguments['testSuffixes'] + ); + } + + if (isset($this->arguments['totalSlices'], $this->arguments['currentSlice'])) { + TestSuiteSlicer::slice($suite, $this->arguments); + } + + $this->arguments['test'] = $suite; + + return $this->run($_SERVER['argv'], $exit); } public function slicesHandler($slices) @@ -50,9 +79,4 @@ protected function showHelp(): void EOT; } - - protected function createRunner(): \PHPUnit\TextUI\TestRunner - { - return new TestRunner($this->arguments['loader']); - } } 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); - } -} diff --git a/tests/Fixtures/ATest.php b/tests/Fixtures/ATest.php new file mode 100644 index 0000000..98e5f18 --- /dev/null +++ b/tests/Fixtures/ATest.php @@ -0,0 +1,14 @@ +addTestFiles([ - __DIR__.'/fixtures/ATest.php', - __DIR__.'/fixtures/BTest.php', - __DIR__.'/fixtures/CTest.php', + __DIR__ . '/Fixtures/ATest.php', + __DIR__ . '/Fixtures/BTest.php', + __DIR__ . '/Fixtures/CTest.php', ]); } @@ -33,7 +34,7 @@ public static function tearDownAfterClass(): void self::$tested = null; } - public function test slice first half() + public function test_slice_first_half() { $suite = clone self::$tested; self::assertCount(19, $suite); @@ -52,20 +53,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', + 'test_A', + 'test_B', + 'test_C', + 'test_D', + 'test_E', + 'test_F', + 'test_G', + 'test_H', + 'test_I', + 'test_J', ], $testsNames); } - public function test slice second half() + public function test_slice_second_half() { $suite = clone self::$tested; self::assertCount(19, $suite); @@ -84,19 +85,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', + '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', ], $testsNames); } - public function test slice last third() + public function test_slice_last_third() { $suite = clone self::$tested; self::assertCount(19, $suite); @@ -115,11 +116,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', + 'test_M with data set #2', + 'test_M with data set #3', + 'test_M with data set #4', + 'test_N', + 'test_O', ], $testsNames); } diff --git a/tests/fixtures/ATest.php b/tests/fixtures/ATest.php deleted file mode 100644 index fa82ad1..0000000 --- a/tests/fixtures/ATest.php +++ /dev/null @@ -1,12 +0,0 @@ - Date: Fri, 2 Oct 2020 12:12:39 +0200 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=91=B7=20replace=20travis=20by=20gith?= =?UTF-8?q?ub=20action?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 14 ++++++++++++++ .travis.yml | 12 ------------ 2 files changed, 14 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..b529b3d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,14 @@ +name: CI + +on: [push] + +jobs: + build-test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + - uses: php-actions/composer@v1 # or alternative dependency management + - name: phpunit + run: | + sudo vendor/bin/phpunit \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 897f229..0000000 --- a/.travis.yml +++ /dev/null @@ -1,12 +0,0 @@ -language: php - -php: - - 7.1 - - 7.2 - - 7.3 - -before_script: - - composer install --no-interaction - -script: - - vendor/bin/phpunit From 5b13677645c81689a5f5dd31ac88fa3240b741c7 Mon Sep 17 00:00:00 2001 From: Hugo Casabella Date: Fri, 2 Oct 2020 16:45:41 +0200 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=8E=A8=20format=20composer.json=20and?= =?UTF-8?q?=20ci.yml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 17 +++++++++++++---- composer.json | 6 +++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b529b3d..86a6747 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,10 +5,19 @@ on: [push] jobs: build-test: runs-on: ubuntu-latest + strategy: + php-versions: [ '7.1', '7.2', '7.3', '7.4' ] + name: PHP ${{ matrix.php-versions }} steps: - - uses: actions/checkout@v1 - - uses: php-actions/composer@v1 # or alternative dependency management + - name: Checkout + uses: actions/checkout@v1 + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + tools: composer:v1 + - name: composer + run: composer install --no-interaction - name: phpunit - run: | - sudo vendor/bin/phpunit \ No newline at end of file + run: vendor/bin/phpunit \ No newline at end of file diff --git a/composer.json b/composer.json index 4a8e4af..5cc6db1 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,11 @@ }, "autoload": { "psr-4": { - "Wizaplace\\PHPUnit\\Slicer\\": "src/", + "Wizaplace\\PHPUnit\\Slicer\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { "Wizaplace\\PHPUnit\\Tests\\Slicer\\": "tests/" } },