| 1 |
<?php |
| 2 |
|
| 3 |
declare( strict_types = 1 ); |
| 4 |
|
| 5 |
namespace MediaWiki\Tests\Unit\composer\PhpUnitSplitter; |
| 6 |
|
| 7 |
use MediaWiki\Composer\PhpUnitSplitter\PhpUnitXml; |
| 8 |
use PHPUnit\Framework\TestCase; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
class PhpUnitXmlTest extends TestCase { |
| 15 |
|
| 16 |
private const BASIC_XML = '<?xml version="1.0" encoding="UTF-8"?> |
| 17 |
<phpunit bootstrap="tests/phpunit/bootstrap.php"> |
| 18 |
<testsuites> |
| 19 |
<testsuite name="core:unit"> |
| 20 |
<directory>tests/phpunit/unit</directory> |
| 21 |
</testsuite> |
| 22 |
</testsuites> |
| 23 |
</phpunit>'; |
| 24 |
|
| 25 |
public function createFixtureFile( string $data ): string { |
| 26 |
$filename = tempnam( sys_get_temp_dir(), "phpunit-test" ); |
| 27 |
file_put_contents( $filename, $data ); |
| 28 |
return $filename; |
| 29 |
} |
| 30 |
|
| 31 |
public function testFixtureContainsNoSplitGroups() { |
| 32 |
$phpUnitXmlFile = $this->createFixtureFile( self::BASIC_XML ); |
| 33 |
$phpUnitXml = new PhpUnitXml( $phpUnitXmlFile ); |
| 34 |
$this->assertFalse( $phpUnitXml->containsSplitGroups(), "No split groups expected in fixture" ); |
| 35 |
unlink( $phpUnitXmlFile ); |
| 36 |
} |
| 37 |
|
| 38 |
public function testAddSplitGroups() { |
| 39 |
$phpUnitXmlFile = $this->createFixtureFile( self::BASIC_XML ); |
| 40 |
$phpUnitXml = new PhpUnitXml( $phpUnitXmlFile ); |
| 41 |
$phpUnitXml->addSplitGroups( [ |
| 42 |
[ "file1.php", "file2.php" ], |
| 43 |
[ "file3.php", "file4.php" ], |
| 44 |
[ "file7.php", "file6.php" ], |
| 45 |
[ "file9.php", "file8.php" ], |
| 46 |
[ "file11.php", "file10.php" ], |
| 47 |
[ "file13.php", "file12.php" ], |
| 48 |
] ); |
| 49 |
$this->assertTrue( $phpUnitXml->containsSplitGroups(), "Expected groups to be added" ); |
| 50 |
unlink( $phpUnitXmlFile ); |
| 51 |
} |
| 52 |
} |