Skip to content

Commit 1405006

Browse files
committed
🎨 mprove command
1 parent 5091187 commit 1405006

File tree

10 files changed

+106
-98
lines changed

10 files changed

+106
-98
lines changed

composer.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
"license": "MIT",
44
"require": {
55
"php": "^7.1",
6-
"phpunit/phpunit": "^7|^8"
6+
"phpunit/phpunit": "^7|^8|^9"
77
},
88
"autoload": {
99
"psr-4": {
10-
"Wizaplace\\PHPUnit\\Slicer\\": "src/"
10+
"Wizaplace\\PHPUnit\\Slicer\\": "src/",
11+
"Wizaplace\\PHPUnit\\Tests\\Slicer\\": "tests/"
1112
}
1213
},
1314
"bin": [

phpunit.xml.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<testsuites>
1010
<testsuite name="Test suite">
1111
<directory>./tests</directory>
12-
<exclude>./tests/fixtures</exclude>
12+
<exclude>./tests/Fixtures</exclude>
1313
</testsuite>
1414
</testsuites>
1515
</phpunit>

src/Command.php

+30-6
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,42 @@
44

55
namespace Wizaplace\PHPUnit\Slicer;
66

7+
use PHPUnit\Framework\TestSuite;
8+
79
class Command extends \PHPUnit\TextUI\Command
810
{
911
public function __construct()
1012
{
1113
$this->longOptions['slices='] = 'slicesHandler';
14+
}
15+
16+
public static function main(bool $exit = true): int
17+
{
18+
return (new static)->runSlicer($_SERVER['argv'], $exit);
19+
}
20+
21+
public function runSlicer(array $argv, bool $exit = true): int
22+
{
23+
$this->handleArguments($argv);
24+
25+
$runner = $this->createRunner();
1226

13-
// there is no parent construct
27+
if ($this->arguments['test'] instanceof TestSuite) {
28+
$suite = $this->arguments['test'];
29+
} else {
30+
$suite = $runner->getTest(
31+
$this->arguments['test'],
32+
$this->arguments['testSuffixes']
33+
);
34+
}
35+
36+
if (isset($this->arguments['totalSlices'], $this->arguments['currentSlice'])) {
37+
TestSuiteSlicer::slice($suite, $this->arguments);
38+
}
39+
40+
$this->arguments['test'] = $suite;
41+
42+
return $this->run($_SERVER['argv'], $exit);
1443
}
1544

1645
public function slicesHandler($slices)
@@ -50,9 +79,4 @@ protected function showHelp(): void
5079
5180
EOT;
5281
}
53-
54-
protected function createRunner(): \PHPUnit\TextUI\TestRunner
55-
{
56-
return new TestRunner($this->arguments['loader']);
57-
}
5882
}

src/TestRunner.php

-24
This file was deleted.

tests/Fixtures/ATest.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Wizaplace\PHPUnit\Tests\Slicer\Fixtures;
6+
7+
use PHPUnit\Framework\TestCase;
8+
9+
class ATest extends TestCase
10+
{
11+
public function test_A() { }
12+
public function test_B() { }
13+
public function test_C() { }
14+
}

tests/Fixtures/BTest.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Wizaplace\PHPUnit\Tests\Slicer\Fixtures;
6+
7+
use PHPUnit\Framework\TestCase;
8+
9+
class BTest extends TestCase
10+
{
11+
public function test_D() { }
12+
public function test_E() { }
13+
public function test_F() { }
14+
public function test_G() { }
15+
public function test_H() { }
16+
}

tests/fixtures/CTest.php tests/Fixtures/CTest.php

+9-7
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22

33
declare(strict_types=1);
44

5+
namespace Wizaplace\PHPUnit\Tests\Slicer\Fixtures;
6+
57
use PHPUnit\Framework\TestCase;
68

79
class CTest extends TestCase
810
{
9-
public function test I() { }
10-
public function test J() { }
11-
public function test K() { }
12-
public function test L() { }
11+
public function test_I() { }
12+
public function test_J() { }
13+
public function test_K() { }
14+
public function test_L() { }
1315

1416
/**
1517
* @dataProvider dataProvider
1618
*/
17-
public function test M($a) { }
19+
public function test_M($a) { }
1820

1921
public function dataProvider()
2022
{
@@ -27,6 +29,6 @@ public function dataProvider()
2729
];
2830
}
2931

30-
public function test N() { }
31-
public function test O() { }
32+
public function test_N() { }
33+
public function test_O() { }
3234
}

tests/TestSuiteSlicerTest.php

+33-32
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
declare(strict_types=1);
44

5-
namespace Wizaplace\PHPUnit\Slicer;
5+
namespace Wizaplace\PHPUnit\Tests\Slicer;
66

77
use PHPUnit\Framework\TestCase;
88
use PHPUnit\Framework\TestSuite;
9+
use Wizaplace\PHPUnit\Slicer\TestSuiteSlicer;
910

10-
class TestSuiteSlicerTest extends TestCase
11+
final class TestSuiteSlicerTest extends TestCase
1112
{
1213
/**
1314
* @var TestSuite
@@ -20,9 +21,9 @@ public static function setUpBeforeClass(): void
2021

2122
self::$tested = new TestSuite();
2223
self::$tested->addTestFiles([
23-
__DIR__.'/fixtures/ATest.php',
24-
__DIR__.'/fixtures/BTest.php',
25-
__DIR__.'/fixtures/CTest.php',
24+
__DIR__ . '/Fixtures/ATest.php',
25+
__DIR__ . '/Fixtures/BTest.php',
26+
__DIR__ . '/Fixtures/CTest.php',
2627
]);
2728
}
2829

@@ -33,7 +34,7 @@ public static function tearDownAfterClass(): void
3334
self::$tested = null;
3435
}
3536

36-
public function test slice first half()
37+
public function test_slice_first_half()
3738
{
3839
$suite = clone self::$tested;
3940
self::assertCount(19, $suite);
@@ -52,20 +53,20 @@ public function test slice first half()
5253
}, $this->extractTestsInSuite($suite));
5354

5455
self::assertEquals([
55-
'test A',
56-
'test B',
57-
'test C',
58-
'test D',
59-
'test E',
60-
'test F',
61-
'test G',
62-
'test H',
63-
'test I',
64-
'test J',
56+
'test_A',
57+
'test_B',
58+
'test_C',
59+
'test_D',
60+
'test_E',
61+
'test_F',
62+
'test_G',
63+
'test_H',
64+
'test_I',
65+
'test_J',
6566
], $testsNames);
6667
}
6768

68-
public function test slice second half()
69+
public function test_slice_second_half()
6970
{
7071
$suite = clone self::$tested;
7172
self::assertCount(19, $suite);
@@ -84,19 +85,19 @@ public function test slice second half()
8485
}, $this->extractTestsInSuite($suite));
8586

8687
self::assertEquals([
87-
'test K',
88-
'test L',
89-
'test M with data set #0',
90-
'test M with data set #1',
91-
'test M with data set #2',
92-
'test M with data set #3',
93-
'test M with data set #4',
94-
'test N',
95-
'test O',
88+
'test_K',
89+
'test_L',
90+
'test_M with data set #0',
91+
'test_M with data set #1',
92+
'test_M with data set #2',
93+
'test_M with data set #3',
94+
'test_M with data set #4',
95+
'test_N',
96+
'test_O',
9697
], $testsNames);
9798
}
9899

99-
public function test slice last third()
100+
public function test_slice_last_third()
100101
{
101102
$suite = clone self::$tested;
102103
self::assertCount(19, $suite);
@@ -115,11 +116,11 @@ public function test slice last third()
115116
}, $this->extractTestsInSuite($suite));
116117

117118
self::assertEquals([
118-
'test M with data set #2',
119-
'test M with data set #3',
120-
'test M with data set #4',
121-
'test N',
122-
'test O',
119+
'test_M with data set #2',
120+
'test_M with data set #3',
121+
'test_M with data set #4',
122+
'test_N',
123+
'test_O',
123124
], $testsNames);
124125
}
125126

tests/fixtures/ATest.php

-12
This file was deleted.

tests/fixtures/BTest.php

-14
This file was deleted.

0 commit comments

Comments
 (0)