From b009d0594d1c4a343480594b97371af41579232d Mon Sep 17 00:00:00 2001 From: Kim Pepper Date: Wed, 13 Aug 2025 10:07:59 +1000 Subject: [PATCH 1/4] Adds phpunit 11 support --- composer.json | 10 +++---- src/GlobbingTestResultCache.php | 2 +- src/SplitterCommand.php | 2 +- .../.phpunit.cache/1/test-results-1.json | 16 +++++++++++ .../.phpunit.cache/2/test-results-2.json | 11 ++++++++ .../.phpunit.cache/test-results-1.json | 1 - .../.phpunit.cache/test-results-2.json | 1 - tests/fixtures/src/FastTestsTest.php | 25 +++++++---------- tests/fixtures/src/ProviderTest.php | 15 +++++------ tests/fixtures/src/SlowTestsTest.php | 27 +++++++------------ tests/src/GlobbingTestResultCacheTest.php | 16 ++++++----- tests/src/PhpUnitSplitterTest.php | 11 ++++---- 12 files changed, 76 insertions(+), 61 deletions(-) create mode 100644 tests/fixtures/.phpunit.cache/1/test-results-1.json create mode 100644 tests/fixtures/.phpunit.cache/2/test-results-2.json delete mode 100644 tests/fixtures/.phpunit.cache/test-results-1.json delete mode 100644 tests/fixtures/.phpunit.cache/test-results-2.json diff --git a/composer.json b/composer.json index 900673f..04956ab 100644 --- a/composer.json +++ b/composer.json @@ -17,15 +17,15 @@ "require": { "php": "^8.1", "ext-simplexml": "*", - "phpstan/phpstan-deprecation-rules": "^1.2", - "phpstan/phpstan-phpunit": "^1.4", "symfony/console": "^6.3|^7.2" }, "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^1.0", + "dealerdirect/phpcodesniffer-composer-installer": "^1.1", "phpstan/extension-installer": "^1.4", - "phpstan/phpstan": "^1.12.19", - "phpunit/phpunit": "^10.5.45", + "phpstan/phpstan": "^2.1", + "phpstan/phpstan-deprecation-rules": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", + "phpunit/phpunit": "^11.5", "previousnext/coding-standard": "^1.1.1", "staabm/annotate-pull-request-from-checkstyle": "^1.8" }, diff --git a/src/GlobbingTestResultCache.php b/src/GlobbingTestResultCache.php index 2602f65..32180bd 100644 --- a/src/GlobbingTestResultCache.php +++ b/src/GlobbingTestResultCache.php @@ -35,7 +35,7 @@ final class GlobbingTestResultCache { * Constructs a new GlobbingTestResultCache. */ public function __construct( - string $filepaths = ".phpunit.cache/test-results*", + string $filepaths = ".phpunit.cache/*/test-results*", ) { $filenames = \glob($filepaths); if ($filenames === FALSE) { diff --git a/src/SplitterCommand.php b/src/SplitterCommand.php index 0b90847..1efea96 100644 --- a/src/SplitterCommand.php +++ b/src/SplitterCommand.php @@ -43,7 +43,7 @@ protected function configure(): void { 'f', InputOption::VALUE_REQUIRED, "The results cache files.", - \getcwd() . '/.phpunit.cache/test-results*', + \getcwd() . '/.phpunit.cache/*/test-results*', ); $this->addOption( 'bootstrap-file', diff --git a/tests/fixtures/.phpunit.cache/1/test-results-1.json b/tests/fixtures/.phpunit.cache/1/test-results-1.json new file mode 100644 index 0000000..fc6728a --- /dev/null +++ b/tests/fixtures/.phpunit.cache/1/test-results-1.json @@ -0,0 +1,16 @@ +{ + "version": 1, + "defects": [], + "times": { + "PhpUnitSplitter\\Tests\\Fixtures\\FastTestsTest::testOne": 0.011, + "PhpUnitSplitter\\Tests\\Fixtures\\FastTestsTest::testTwo": 0.02, + "PhpUnitSplitter\\Tests\\Fixtures\\FastTestsTest::testThree": 0.03, + "PhpUnitSplitter\\Tests\\Fixtures\\FastTestsTest::testFour": 0.04, + "PhpUnitSplitter\\Tests\\Fixtures\\FastTestsTest::testFive": 0.05, + "PhpUnitSplitter\\Tests\\Fixtures\\ProviderTest::testProvider with data set \"one\"": 0.111, + "PhpUnitSplitter\\Tests\\Fixtures\\ProviderTest::testProvider with data set \"two\"": 0.445, + "PhpUnitSplitter\\Tests\\Fixtures\\ProviderTest::testProvider with data set \"three\"": 0.222, + "PhpUnitSplitter\\Tests\\Fixtures\\ProviderTest::testProvider with data set \"four\"": 0.334, + "PhpUnitSplitter\\Tests\\Fixtures\\ProviderTest::testProvider with data set \"five\"": 0.667 + } +} diff --git a/tests/fixtures/.phpunit.cache/2/test-results-2.json b/tests/fixtures/.phpunit.cache/2/test-results-2.json new file mode 100644 index 0000000..222a8e7 --- /dev/null +++ b/tests/fixtures/.phpunit.cache/2/test-results-2.json @@ -0,0 +1,11 @@ +{ + "version": 1, + "defects": [], + "times": { + "PhpUnitSplitter\\Tests\\Fixtures\\SlowTestsTest::testOne": 0.101, + "PhpUnitSplitter\\Tests\\Fixtures\\SlowTestsTest::testTwo": 0.2, + "PhpUnitSplitter\\Tests\\Fixtures\\SlowTestsTest::testThree": 0.3, + "PhpUnitSplitter\\Tests\\Fixtures\\SlowTestsTest::testFour": 0.4, + "PhpUnitSplitter\\Tests\\Fixtures\\SlowTestsTest::testFive": 0.5 + } +} diff --git a/tests/fixtures/.phpunit.cache/test-results-1.json b/tests/fixtures/.phpunit.cache/test-results-1.json deleted file mode 100644 index ea6bc23..0000000 --- a/tests/fixtures/.phpunit.cache/test-results-1.json +++ /dev/null @@ -1 +0,0 @@ -{"version":1,"defects":[],"times":{"PhpUnitSplitter\\Tests\\Fixtures\\FastTestsTest::testOne":0.011,"PhpUnitSplitter\\Tests\\Fixtures\\FastTestsTest::testTwo":0.02,"PhpUnitSplitter\\Tests\\Fixtures\\FastTestsTest::testThree":0.03,"PhpUnitSplitter\\Tests\\Fixtures\\FastTestsTest::testFour":0.04,"PhpUnitSplitter\\Tests\\Fixtures\\FastTestsTest::testFive":0.05,"PhpUnitSplitter\\Tests\\Fixtures\\ProviderTest::testProvider with data set \"one\"":0.111,"PhpUnitSplitter\\Tests\\Fixtures\\ProviderTest::testProvider with data set \"two\"":0.445,"PhpUnitSplitter\\Tests\\Fixtures\\ProviderTest::testProvider with data set \"three\"":0.222,"PhpUnitSplitter\\Tests\\Fixtures\\ProviderTest::testProvider with data set \"four\"":0.334,"PhpUnitSplitter\\Tests\\Fixtures\\ProviderTest::testProvider with data set \"five\"":0.667}} \ No newline at end of file diff --git a/tests/fixtures/.phpunit.cache/test-results-2.json b/tests/fixtures/.phpunit.cache/test-results-2.json deleted file mode 100644 index 8b90ea2..0000000 --- a/tests/fixtures/.phpunit.cache/test-results-2.json +++ /dev/null @@ -1 +0,0 @@ -{"version":1,"defects":[],"times":{"PhpUnitSplitter\\Tests\\Fixtures\\SlowTestsTest::testOne":0.101,"PhpUnitSplitter\\Tests\\Fixtures\\SlowTestsTest::testTwo":0.2,"PhpUnitSplitter\\Tests\\Fixtures\\SlowTestsTest::testThree":0.3,"PhpUnitSplitter\\Tests\\Fixtures\\SlowTestsTest::testFour":0.4,"PhpUnitSplitter\\Tests\\Fixtures\\SlowTestsTest::testFive":0.5}} \ No newline at end of file diff --git a/tests/fixtures/src/FastTestsTest.php b/tests/fixtures/src/FastTestsTest.php index 4c9dcc9..badba6a 100644 --- a/tests/fixtures/src/FastTestsTest.php +++ b/tests/fixtures/src/FastTestsTest.php @@ -1,51 +1,44 @@ assertTrue(TRUE); } - /** - * @covers ::testTwo - */ + #[Test] public function testTwo(): void { \usleep(20000); $this->assertTrue(TRUE); } - /** - * @covers ::testThree - */ + #[Test] public function testThree(): void { \usleep(30000); $this->assertTrue(TRUE); } - /** - * @covers ::testFour - */ + #[Test] public function testFour(): void { \usleep(40000); $this->assertTrue(TRUE); } - /** - * @covers ::testFive - */ + #[Test] public function testFive(): void { \usleep(50000); $this->assertTrue(TRUE); diff --git a/tests/fixtures/src/ProviderTest.php b/tests/fixtures/src/ProviderTest.php index c3de5ee..f06f796 100644 --- a/tests/fixtures/src/ProviderTest.php +++ b/tests/fixtures/src/ProviderTest.php @@ -4,26 +4,25 @@ namespace PhpUnitSplitter\Tests\Fixtures; +use PHPUnit\Framework\Attributes\CoversNothing; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; /** * Simulates a provider test. */ +#[CoversNothing] class ProviderTest extends TestCase { - /** - * @dataProvider provider - * @covers ::testProvider - */ + #[Test] + #[DataProvider('provider')] public function testProvider(int $sleep): void { \usleep($sleep); $this->assertTrue(TRUE); } - /** - * - */ - public function provider(): array { + public static function provider(): array { return [ 'one' => [111111], 'two' => [444444], diff --git a/tests/fixtures/src/SlowTestsTest.php b/tests/fixtures/src/SlowTestsTest.php index 8560ae2..28ff2fe 100644 --- a/tests/fixtures/src/SlowTestsTest.php +++ b/tests/fixtures/src/SlowTestsTest.php @@ -4,50 +4,43 @@ namespace PhpUnitSplitter\Tests\Fixtures; +use PHPUnit\Framework\Attributes\CoversNothing; +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; /** * Simulates a slow test. - * - * @group slow */ +#[CoversNothing] +#[Group('slow')] class SlowTestsTest extends TestCase { - /** - * @covers ::testOne - */ + #[Test] public function testOne(): void { \usleep(100000); $this->assertTrue(TRUE); } - /** - * @covers ::testTwo - */ + #[Test] public function testTwo(): void { \usleep(200000); $this->assertTrue(TRUE); } - /** - * @covers ::testThree - */ + #[Test] public function testThree(): void { \usleep(300000); $this->assertTrue(TRUE); } - /** - * @covers ::testFour - */ + #[Test] public function testFour(): void { \usleep(400000); $this->assertTrue(TRUE); } - /** - * @covers ::testFive - */ + #[Test] public function testFive(): void { \usleep(500000); $this->assertTrue(TRUE); diff --git a/tests/src/GlobbingTestResultCacheTest.php b/tests/src/GlobbingTestResultCacheTest.php index 8089cbc..44857ef 100644 --- a/tests/src/GlobbingTestResultCacheTest.php +++ b/tests/src/GlobbingTestResultCacheTest.php @@ -4,19 +4,23 @@ namespace PhpUnitSplitter\Tests; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use PhpUnitSplitter\GlobbingTestResultCache; /** - * @coversDefaultClass \PhpUnitSplitter\GlobbingTestResultCache + * Tests for the GlobbingTestResultCache class. */ +#[CoversClass(GlobbingTestResultCache::class)] class GlobbingTestResultCacheTest extends TestCase { - /** - * @covers ::load - */ - public function testLoadFile(): void { - $cache = new GlobbingTestResultCache(\dirname(__DIR__) . '/fixtures/.phpunit.cache/test-results*'); + /** + * Tests loading multiple cache files. + */ + #[Test] + public function testLoadFile(): void { + $cache = new GlobbingTestResultCache(\dirname(__DIR__) . '/fixtures/.phpunit.cache/*/test-results*'); $cache->load(); // Assert we get test times for both cache files. $this->assertEquals(0.011, $cache->getTime('PhpUnitSplitter\Tests\Fixtures\FastTestsTest::testOne')); diff --git a/tests/src/PhpUnitSplitterTest.php b/tests/src/PhpUnitSplitterTest.php index 2b5fae0..0df7d4a 100644 --- a/tests/src/PhpUnitSplitterTest.php +++ b/tests/src/PhpUnitSplitterTest.php @@ -4,20 +4,21 @@ namespace PhpUnitSplitter\Tests; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use PhpUnitSplitter\TestMapper; /** - * @coversDefaultClass \PhpUnitSplitter\TestMapper + * Tests for the TestMapper class. */ +#[CoversClass(TestMapper::class)] class PhpUnitSplitterTest extends TestCase { - /** - * @covers ::getMap - */ + #[Test] public function testSplitter(): void { $fixtures = \dirname(__DIR__) . '/fixtures'; - $mapper = new TestMapper("$fixtures/tests.xml", "$fixtures/.phpunit.cache/test-results*", \dirname(__DIR__, 2) . '/'); + $mapper = new TestMapper("$fixtures/tests.xml", "$fixtures/.phpunit.cache/*/test-results*", \dirname(__DIR__, 2) . '/'); $map = $mapper->getMap(); $this->assertSame([ From 1f9e80abaf1a90f8722186630a6d85266d80ab32 Mon Sep 17 00:00:00 2001 From: Kim Pepper Date: Wed, 13 Aug 2025 10:10:49 +1000 Subject: [PATCH 2/4] Fix phpcs --- tests/src/GlobbingTestResultCacheTest.php | 10 +++++----- tests/src/PhpUnitSplitterTest.php | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/src/GlobbingTestResultCacheTest.php b/tests/src/GlobbingTestResultCacheTest.php index 44857ef..5593c9b 100644 --- a/tests/src/GlobbingTestResultCacheTest.php +++ b/tests/src/GlobbingTestResultCacheTest.php @@ -15,11 +15,11 @@ #[CoversClass(GlobbingTestResultCache::class)] class GlobbingTestResultCacheTest extends TestCase { - /** - * Tests loading multiple cache files. - */ - #[Test] - public function testLoadFile(): void { + /** + * Tests loading multiple cache files. + */ + #[Test] + public function testLoadFile(): void { $cache = new GlobbingTestResultCache(\dirname(__DIR__) . '/fixtures/.phpunit.cache/*/test-results*'); $cache->load(); // Assert we get test times for both cache files. diff --git a/tests/src/PhpUnitSplitterTest.php b/tests/src/PhpUnitSplitterTest.php index 0df7d4a..aeb1fc6 100644 --- a/tests/src/PhpUnitSplitterTest.php +++ b/tests/src/PhpUnitSplitterTest.php @@ -15,6 +15,9 @@ #[CoversClass(TestMapper::class)] class PhpUnitSplitterTest extends TestCase { + /** + * Tests the splitter functionality of the TestMapper class. + */ #[Test] public function testSplitter(): void { $fixtures = \dirname(__DIR__) . '/fixtures'; From a11391b0dabbf2e95d0deb34dc5e42b47a6b7b91 Mon Sep 17 00:00:00 2001 From: Kim Pepper Date: Wed, 13 Aug 2025 10:15:44 +1000 Subject: [PATCH 3/4] Update phpstan ignore --- phpstan-baseline.neon | 7 +++++++ phpstan.neon | 3 +++ 2 files changed, 10 insertions(+) create mode 100644 phpstan-baseline.neon diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..571333d --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,7 @@ +parameters: + ignoreErrors: + - + message: '#^Method PhpUnitSplitter\\TestMapper\:\:getMap\(\) should return array\\> but returns array\\>\|string\>\>\.$#' + identifier: return.type + count: 1 + path: src/TestMapper.php diff --git a/phpstan.neon b/phpstan.neon index 7faf474..531000e 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,3 +1,6 @@ +includes: + - phpstan-baseline.neon + parameters: level: 6 paths: From 8b63b11a9ca6c1f16b3ba8a49e6e249a5f7bb47e Mon Sep 17 00:00:00 2001 From: Kim Pepper Date: Wed, 13 Aug 2025 10:21:37 +1000 Subject: [PATCH 4/4] Allow phpunit 10 also --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 04956ab..bd63e86 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "phpstan/phpstan": "^2.1", "phpstan/phpstan-deprecation-rules": "^2.0", "phpstan/phpstan-phpunit": "^2.0", - "phpunit/phpunit": "^11.5", + "phpunit/phpunit": "^10.5.51|^11.5.32", "previousnext/coding-standard": "^1.1.1", "staabm/annotate-pull-request-from-checkstyle": "^1.8" },