3declare( strict_types = 1 );
7use Composer\IO\IOInterface;
10use Shellbox\Command\UnboxedExecutor;
11use Shellbox\Command\UnboxedResult;
18 private UnboxedExecutor $executor;
19 private ?IOInterface $io;
21 private string $phpunitConfigFile;
24 string $phpunitConfigFile,
25 UnboxedExecutor $shellExecutor,
29 $this->phpunitConfigFile = $phpunitConfigFile;
30 $this->executor = $shellExecutor;
39 ?
string $resultsCacheFile =
null,
42 $command = $this->executor->createCommand()
48 '--configuration', $this->phpunitConfigFile,
49 '--testsuite', $testSuite,
50 '--exclude-group', implode(
",", $excludeGroups )
52 if ( count( $groups ) ) {
53 $command->params(
'--group', implode(
',', $groups ) );
55 if ( $resultsCacheFile ) {
57 "--cache-result-file=$resultsCacheFile"
60 $command->includeStderr(
true );
61 if ( $groupId !==
null ) {
62 $command->environment( [
'MW_PHPUNIT_SPLIT_GROUP_ID' => $groupId ] );
64 $this->consoleLog(
"Running command '" . $command->getCommandString() .
"' ..." . PHP_EOL );
65 return $command->execute();
68 private function warning(
string $warning ) {
70 $this->io->warning( $warning );
74 private function composerLog(
string $text ) {
76 $this->io->write( $text );
80 private function consoleLog(
string $outputText ) {
81 $this->composerSystemInterface->print( $outputText );
85 $this->warning(
"Test suite splitting failed - falling back to linear run" );
86 $this->composerLog(
"Running " . $testSuite .
" phpunit suite databaseless tests..." );
87 $databaselessResult = $this->executeSplitGroup(
92 $this->consoleLog( $databaselessResult->getStdout() );
93 if ( $databaselessResult->getExitCode() !== 0 ) {
96 $this->composerLog(
"Running " . $testSuite .
" phpunit suite database tests..." );
97 $databaseResult = $this->executeSplitGroup(
102 $this->consoleLog( $databaseResult->getStdout() );