1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
<?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 {
public function setUp(): void {
if ( !extension_loaded( 'pcntl' ) && !extension_loaded( 'posix' ) ) {
$this->markTestSkipped( 'need extension pcntl or posix' );
}
}
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() {
$logDir = getenv( 'MW_LOG_DIR' ) ?? '.';
$executor = $this->createMock( SplitGroupExecutor::class );
$systemInterface = $this->getMockSystemInterface( 'phpunit_output_1_database.log' );
$composerLaunchParallel = new ComposerLaunchParallel(
"phpunit-database.xml",
[ 'Database' ],
[ 'Broken' ],
null,
$executor,
$systemInterface
);
$result = $this->getMockCommandResult();
$executor->expects( $this->once() )
->method( 'executeSplitGroup' )
->with( 'split_group_1',
[ 'Database' ],
[ 'Broken' ],
$logDir . "/phpunit_group_1_database.result.cache",
1
)
->willReturn( $result );
$wrapper = TestingAccessWrapper::newFromObject( $composerLaunchParallel );
$wrapper->runTestSuite( 1 );
}
public function testExecuteDatabaselessSuite() {
$logDir = getenv( 'MW_LOG_DIR' ) ?? '.';
$executor = $this->createMock( SplitGroupExecutor::class );
$systemInterface = $this->getMockSystemInterface( 'phpunit_output_1_databaseless.log' );
$composerLaunchParallel = new ComposerLaunchParallel(
"phpunit-databaseless.xml",
[],
[ 'Broken', 'Standalone', 'Database' ],
null,
$executor,
$systemInterface
);
$result = $this->getMockCommandResult();
$executor->expects( $this->once() )
->method( 'executeSplitGroup' )
->with( 'split_group_1',
[],
[ 'Broken', 'Standalone', 'Database' ],
$logDir . "/phpunit_group_1_databaseless.result.cache",
1
)
->willReturn( $result );
$wrapper = TestingAccessWrapper::newFromObject( $composerLaunchParallel );
$wrapper->runTestSuite( 1 );
}
}
|