diff options
author | Arthur Taylor <arthur.taylor@wikimedia.de> | 2024-12-02 14:02:27 +0100 |
---|---|---|
committer | Arthur Taylor <arthur.taylor@wikimedia.de> | 2024-12-03 10:36:14 +0100 |
commit | 57d9755ff714096cae4b0f3e39b878f1adbf99c0 (patch) | |
tree | 4989595636d73bcf8bf2006cf716658229c7421e /tests/phpunit/unit/includes/composer/PhpUnitSplitter | |
parent | 4ba476a3cc499391e0f04bb1f809af77e2463ada (diff) | |
download | mediawikicore-57d9755ff714096cae4b0f3e39b878f1adbf99c0.tar.gz mediawikicore-57d9755ff714096cae4b0f3e39b878f1adbf99c0.zip |
Fix missing split group error log output
Changes introduced in I550b11f81c15eba01359c30e5c59db0715afd4cd for
T379764 resulted in the log files for the phpunit split groups
being generated with invalid names (`phpunit_output_1_1.log` instead
of `phpunit_output_1_database.log`). This meant the
PhpUnitConsoleLogOutputProcessor was no longer able to find the log
files to present a summary at the end of a failed run.
This patch fixes the bug, and also goes some way to refactoring the
code to make it more testable and debuggable.
Bug: T378481
Change-Id: I0c345ea56529e6768f80a00440e9a13aa05ad069
Diffstat (limited to 'tests/phpunit/unit/includes/composer/PhpUnitSplitter')
-rw-r--r-- | tests/phpunit/unit/includes/composer/PhpUnitSplitter/SplitGroupExecutorTest.php | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/phpunit/unit/includes/composer/PhpUnitSplitter/SplitGroupExecutorTest.php b/tests/phpunit/unit/includes/composer/PhpUnitSplitter/SplitGroupExecutorTest.php new file mode 100644 index 000000000000..06d17a13948a --- /dev/null +++ b/tests/phpunit/unit/includes/composer/PhpUnitSplitter/SplitGroupExecutorTest.php @@ -0,0 +1,66 @@ +<?php + +declare( strict_types = 1 ); + +namespace MediaWiki\Tests\Unit\composer\PhpUnitSplitter; + +use MediaWiki\Composer\ComposerSystemInterface; +use MediaWiki\Composer\PhpUnitSplitter\SplitGroupExecutor; +use PHPUnit\Framework\TestCase; +use Shellbox\Command\UnboxedCommand; +use Shellbox\Command\UnboxedExecutor; +use Shellbox\Command\UnboxedResult; + +/** + * @license GPL-2.0-or-later + * @covers \MediaWiki\Composer\ComposerLaunchParallel + */ +class SplitGroupExecutorTest extends TestCase { + + private SplitGroupExecutor $splitGroupExecutor; + private array $collectedArgs = []; + + public function setUp(): void { + parent::setUp(); + $commandMock = $this->createMock( UnboxedCommand::class ); + $executor = $this->createMock( UnboxedExecutor::class ); + $executor->expects( $this->once() ) + ->method( 'createCommand' ) + ->willReturn( $commandMock ); + $commandMock + ->method( 'params' ) + ->willReturnCallback( function ( ...$args ) use ( $commandMock ) { + $this->collectedArgs = array_merge( $this->collectedArgs, $args ); + return $commandMock; + } ); + $commandMock->method( 'execute' ) + ->willReturn( $this->createMock( UnboxedResult::class ) ); + $interface = $this->createMock( ComposerSystemInterface::class ); + $this->splitGroupExecutor = new SplitGroupExecutor( $executor, null, $interface ); + } + + public function testExecuteDatabaseSuite() { + $this->splitGroupExecutor->executeSplitGroup( + "extensions", + [ "Database" ], + [ "Broken" ] + ); + $this->assertEquals( [ + "composer", "run", "--timeout=0", "phpunit:entrypoint", "--", + "--testsuite", "extensions", "--exclude-group", "Broken", + "--group", "Database" ], + $this->collectedArgs ); + } + + public function testExecuteDatabaselessSuite() { + $this->splitGroupExecutor->executeSplitGroup( + "extensions", + [], + [ "Broken", "Standalone" ] + ); + $this->assertEquals( [ + "composer", "run", "--timeout=0", "phpunit:entrypoint", "--", + "--testsuite", "extensions", "--exclude-group", "Broken,Standalone" ], + $this->collectedArgs ); + } +} |