aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/unit/includes/composer
diff options
context:
space:
mode:
authorArthur Taylor <arthur.taylor@wikimedia.de>2024-12-02 14:02:27 +0100
committerArthur Taylor <arthur.taylor@wikimedia.de>2024-12-03 10:36:14 +0100
commit57d9755ff714096cae4b0f3e39b878f1adbf99c0 (patch)
tree4989595636d73bcf8bf2006cf716658229c7421e /tests/phpunit/unit/includes/composer
parent4ba476a3cc499391e0f04bb1f809af77e2463ada (diff)
downloadmediawikicore-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')
-rw-r--r--tests/phpunit/unit/includes/composer/ComposerLaunchParallelTest.php87
-rw-r--r--tests/phpunit/unit/includes/composer/PhpUnitSplitter/SplitGroupExecutorTest.php66
2 files changed, 153 insertions, 0 deletions
diff --git a/tests/phpunit/unit/includes/composer/ComposerLaunchParallelTest.php b/tests/phpunit/unit/includes/composer/ComposerLaunchParallelTest.php
new file mode 100644
index 000000000000..1a7c1d8c13fa
--- /dev/null
+++ b/tests/phpunit/unit/includes/composer/ComposerLaunchParallelTest.php
@@ -0,0 +1,87 @@
+<?php
+
+declare( strict_types = 1 );
+
+namespace MediaWiki\Tests\Unit\composer;
+
+use MediaWiki\Composer\ComposerLaunchParallel;
+use MediaWiki\Composer\ComposerSystemInterface;
+use MediaWiki\Composer\PhpUnitSplitter\SplitGroupExecutor;
+use PHPUnit\Framework\TestCase;
+use Shellbox\Command\UnboxedResult;
+use Wikimedia\TestingAccessWrapper;
+
+/**
+ * @license GPL-2.0-or-later
+ * @covers \MediaWiki\Composer\ComposerLaunchParallel
+ */
+class ComposerLaunchParallelTest extends TestCase {
+
+ private function getMockCommandResult(): UnboxedResult {
+ $result = $this->createMock( UnboxedResult::class );
+ $result->method( 'getStdout' )
+ ->willReturn( 'logs from test' );
+ $result->method( 'getExitCode' )
+ ->willReturn( 1 );
+ return $result;
+ }
+
+ private function getMockSystemInterface( string $logFileName ): ComposerSystemInterface {
+ $systemInterface = $this->createMock( ComposerSystemInterface::class );
+ $systemInterface->expects( $this->once() )
+ ->method( 'exit' )
+ ->with( 1 );
+ $systemInterface->expects( $this->once() )
+ ->method( 'putFileContents' )
+ ->with( $logFileName, 'logs from test' );
+ return $systemInterface;
+ }
+
+ public function testExecuteDatabaseSuite() {
+ $executor = $this->createMock( SplitGroupExecutor::class );
+ $systemInterface = $this->getMockSystemInterface( 'phpunit_output_1_database.log' );
+ $composerLaunchParallel = new ComposerLaunchParallel(
+ [ 'Database' ],
+ [ 'Broken' ],
+ null,
+ $executor,
+ $systemInterface
+ );
+ $result = $this->getMockCommandResult();
+ $executor->expects( $this->once() )
+ ->method( 'executeSplitGroup' )
+ ->with( 'split_group_1',
+ [ 'Database' ],
+ [ 'Broken' ],
+ ".phpunit_group_1_database.result.cache",
+ 1
+ )
+ ->willReturn( $result );
+ $wrapper = TestingAccessWrapper::newFromObject( $composerLaunchParallel );
+ $wrapper->runTestSuite( 1 );
+ }
+
+ public function testExecuteDatabaselessSuite() {
+ $executor = $this->createMock( SplitGroupExecutor::class );
+ $systemInterface = $this->getMockSystemInterface( 'phpunit_output_1_databaseless.log' );
+ $composerLaunchParallel = new ComposerLaunchParallel(
+ [],
+ [ 'Broken', 'Standalone', 'Database' ],
+ null,
+ $executor,
+ $systemInterface
+ );
+ $result = $this->getMockCommandResult();
+ $executor->expects( $this->once() )
+ ->method( 'executeSplitGroup' )
+ ->with( 'split_group_1',
+ [],
+ [ 'Broken', 'Standalone', 'Database' ],
+ ".phpunit_group_1_databaseless.result.cache",
+ 1
+ )
+ ->willReturn( $result );
+ $wrapper = TestingAccessWrapper::newFromObject( $composerLaunchParallel );
+ $wrapper->runTestSuite( 1 );
+ }
+}
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 );
+ }
+}