3declare( strict_types = 1 );
7use Composer\Script\Event;
10use Shellbox\Command\UnboxedExecutor;
11use Shellbox\Command\UnboxedResult;
18 private UnboxedExecutor $executor;
19 private ?Event $event;
23 UnboxedExecutor $shellExecutor,
27 $this->executor = $shellExecutor;
28 $this->
event = $event;
36 ?
string $resultsCacheFile =
null,
39 $command = $this->executor->createCommand()
45 '--testsuite', $testSuite,
46 '--exclude-group', implode(
",", $excludeGroups )
48 if ( count( $groups ) ) {
49 $command->params(
'--group', implode(
',', $groups ) );
51 if ( $resultsCacheFile ) {
53 "--cache-result-file=$resultsCacheFile"
56 $command->includeStderr(
true );
57 if ( $groupId !==
null ) {
58 $command->environment( [
'MW_PHPUNIT_SPLIT_GROUP_ID' => $groupId ] );
60 $this->consoleLog(
"Running command '" . $command->getCommandString() .
"' ..." . PHP_EOL );
61 return $command->execute();
64 private function warning(
string $warning ) {
66 $this->
event->getIO()->warning( $warning );
70 private function composerLog(
string $text ) {
72 $this->
event->getIO()->write( $text );
76 private function consoleLog(
string $outputText ) {
77 $this->composerSystemInterface->print( $outputText );
81 $this->warning(
"Test suite splitting failed - falling back to linear run" );
82 $this->composerLog(
"Running " . $testSuite .
" phpunit suite databaseless tests..." );
83 $databaselessResult = $this->executeSplitGroup(
88 $this->consoleLog( $databaselessResult->getStdout() );
89 if ( $databaselessResult->getExitCode() !== 0 ) {
92 $this->composerLog(
"Running " . $testSuite .
" phpunit suite database tests..." );
93 $databaseResult = $this->executeSplitGroup(
98 $this->consoleLog( $databaseResult->getStdout() );