#!/usr/bin/env php mustRun(); $tests = \Illuminate\Support\Str::of($process->getOutput()) ->explode("\n") // Break the output from new lines into an array ->filter(fn (string $test) => str_contains($test, ' - ')) // Only lines with " - " ->map(fn (string $test) => addslashes( \Illuminate\Support\Str::of($test) ->replace('- ', '') // Strip the "- " ->trim() ->explode('::') // Only the class, not the method ->get(0) )) ->filter(fn (string $test) => !empty($test)) // Make sure there are no empty lines ->unique() // We only need unique classes ->split((int) getenv('CI_NODE_TOTAL')) // Split it into equally sized chunks ->get((int) getenv('CI_NODE_INDEX')); // Get the index we need for this instance /** * Run phpunit with a filter: * phpunit --filter 'TestClass|AnotherTestClass|...' */ $process = new \Symfony\Component\Process\Process(['./vendor/bin/phpunit', '--testdox', '--filter', $tests->join('|')], timeout: null); $process->start(); // Make sure we have live data output foreach ($process as $type => $data) { echo $data; } $process->wait(); // Exit using PHPUnit's exit code to have the action pass/fail exit($process->getExitCode());