Skip to content
Merged
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
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "^10.5.51|^11.5.32",
"previousnext/coding-standard": "^1.1.1",
"staabm/annotate-pull-request-from-checkstyle": "^1.8"
},
Expand Down
7 changes: 7 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
parameters:
ignoreErrors:
-
message: '#^Method PhpUnitSplitter\\TestMapper\:\:getMap\(\) should return array\<string, array\<string, float\>\> but returns array\<int\|string, array\<string, float\|list\<array\<string, float\|string\>\>\|string\>\>\.$#'
identifier: return.type
count: 1
path: src/TestMapper.php
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
includes:
- phpstan-baseline.neon

parameters:
level: 6
paths:
Expand Down
2 changes: 1 addition & 1 deletion src/GlobbingTestResultCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/SplitterCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
16 changes: 16 additions & 0 deletions tests/fixtures/.phpunit.cache/1/test-results-1.json
Original file line number Diff line number Diff line change
@@ -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
}
}
11 changes: 11 additions & 0 deletions tests/fixtures/.phpunit.cache/2/test-results-2.json
Original file line number Diff line number Diff line change
@@ -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
}
}
1 change: 0 additions & 1 deletion tests/fixtures/.phpunit.cache/test-results-1.json

This file was deleted.

1 change: 0 additions & 1 deletion tests/fixtures/.phpunit.cache/test-results-2.json

This file was deleted.

25 changes: 9 additions & 16 deletions tests/fixtures/src/FastTestsTest.php
Original file line number Diff line number Diff line change
@@ -1,51 +1,44 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace PhpUnitSplitter\Tests\Fixtures;

use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

/**
* Simulates a fast test.
*/
#[CoversNothing]
class FastTestsTest extends TestCase {

/**
* @covers ::testOne
*/
#[Test]
public function testOne(): void {
\usleep(10000);
$this->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);
Expand Down
15 changes: 7 additions & 8 deletions tests/fixtures/src/ProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
27 changes: 10 additions & 17 deletions tests/fixtures/src/SlowTestsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 7 additions & 3 deletions tests/src/GlobbingTestResultCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
* Tests loading multiple cache files.
*/
#[Test]
public function testLoadFile(): void {
$cache = new GlobbingTestResultCache(\dirname(__DIR__) . '/fixtures/.phpunit.cache/test-results*');
$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'));
Expand Down
10 changes: 7 additions & 3 deletions tests/src/PhpUnitSplitterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@

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
* Tests the splitter functionality of the TestMapper class.
*/
#[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([
Expand Down