Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎨 Improve slicer to phpunit9 #10

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: CI

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:
- 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: vendor/bin/phpunit
12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
"license": "MIT",
"require": {
"php": "^7.1",
"phpunit/phpunit": "^7|^8"
"phpunit/phpunit": "^7|^8|^9"
},
"autoload": {
"psr-4": {
"Wizaplace\\PHPUnit\\Slicer\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Wizaplace\\PHPUnit\\Tests\\Slicer\\": "tests/"
}
},
"bin": [
"phpunit-slicer"
]
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<testsuites>
<testsuite name="Test suite">
<directory>./tests</directory>
<exclude>./tests/fixtures</exclude>
<exclude>./tests/Fixtures</exclude>
</testsuite>
</testsuites>
</phpunit>
36 changes: 30 additions & 6 deletions src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -50,9 +79,4 @@ protected function showHelp(): void

EOT;
}

protected function createRunner(): \PHPUnit\TextUI\TestRunner
{
return new TestRunner($this->arguments['loader']);
}
}
24 changes: 0 additions & 24 deletions src/TestRunner.php

This file was deleted.

14 changes: 14 additions & 0 deletions tests/Fixtures/ATest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace Wizaplace\PHPUnit\Tests\Slicer\Fixtures;

use PHPUnit\Framework\TestCase;

class ATest extends TestCase
{
public function test_A() { }
public function test_B() { }
public function test_C() { }
}
16 changes: 16 additions & 0 deletions tests/Fixtures/BTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Wizaplace\PHPUnit\Tests\Slicer\Fixtures;

use PHPUnit\Framework\TestCase;

class BTest extends TestCase
{
public function test_D() { }
public function test_E() { }
public function test_F() { }
public function test_G() { }
public function test_H() { }
}
16 changes: 9 additions & 7 deletions tests/fixtures/CTest.php → tests/Fixtures/CTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@

declare(strict_types=1);

namespace Wizaplace\PHPUnit\Tests\Slicer\Fixtures;

use PHPUnit\Framework\TestCase;

class CTest extends TestCase
{
public function test I() { }
public function test J() { }
public function test K() { }
public function test L() { }
public function test_I() { }
public function test_J() { }
public function test_K() { }
public function test_L() { }

/**
* @dataProvider dataProvider
*/
public function test M($a) { }
public function test_M($a) { }

public function dataProvider()
{
Expand All @@ -27,6 +29,6 @@ public function dataProvider()
];
}

public function test N() { }
public function test O() { }
public function test_N() { }
public function test_O() { }
}
65 changes: 33 additions & 32 deletions tests/TestSuiteSlicerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

declare(strict_types=1);

namespace Wizaplace\PHPUnit\Slicer;
namespace Wizaplace\PHPUnit\Tests\Slicer;

use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestSuite;
use Wizaplace\PHPUnit\Slicer\TestSuiteSlicer;

class TestSuiteSlicerTest extends TestCase
final class TestSuiteSlicerTest extends TestCase
{
/**
* @var TestSuite
Expand All @@ -20,9 +21,9 @@ public static function setUpBeforeClass(): void

self::$tested = new TestSuite();
self::$tested->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',
]);
}

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
}

Expand Down
12 changes: 0 additions & 12 deletions tests/fixtures/ATest.php

This file was deleted.

14 changes: 0 additions & 14 deletions tests/fixtures/BTest.php

This file was deleted.