diff --git a/bin/pest b/bin/pest index 2223cffd..f2e14f32 100755 --- a/bin/pest +++ b/bin/pest @@ -4,9 +4,9 @@ use NunoMaduro\Collision\Provider; use ParaTest\Console\Commands\ParaTestCommand; use Pest\Actions\LoadStructure; +use Pest\Actions\MapArguments; use Pest\Actions\ValidatesEnvironment; use Pest\Console\Command; -use Pest\Console\Paratest\Runner; use Pest\Support\Container; use Pest\TestSuite; use Symfony\Component\Console\Input\ArgvInput; @@ -36,20 +36,6 @@ use Symfony\Component\Console\Output\OutputInterface; $testSuite = TestSuite::getInstance($rootPath, $argv->getParameterOption('--test-directory', 'tests')); - $shouldExecuteInParallel = $argv->hasParameterOption('--parallel'); - // Let's remove the parallel option now we've retrieved its value - if (($parallelKey = array_search('--parallel', $_SERVER['argv'])) !== false) { - unset($_SERVER['argv'][$parallelKey]); - } - - if ($argv->hasParameterOption('--isInParallel')) { - $testSuite->isInParallel = true; - } - // Let's remove the parallel flag now we've retrieved its value - if (($parallelKey = array_search('--isInParallel', $_SERVER['argv'])) !== false) { - unset($_SERVER['argv'][$parallelKey]); - } - $isDecorated = $argv->getParameterOption('--colors', 'always') !== 'never'; $output = new ConsoleOutput(ConsoleOutput::VERBOSITY_NORMAL, $isDecorated); @@ -68,13 +54,13 @@ use Symfony\Component\Console\Output\OutputInterface; } } - if ($shouldExecuteInParallel) { - $_SERVER['argv'][] = '--runner'; - $_SERVER['argv'][] = Runner::class; - + if ($argv->hasParameterOption('--parallel')) { LoadStructure::in($testSuite->rootPath); + MapArguments::toParatest($testSuite); exit(ParaTestCommand::applicationFactory($testSuite->rootPath)->run(new ArgvInput())); } + MapArguments::toPest($testSuite); + exit($container->get(Command::class)->run($_SERVER['argv'])); })(); diff --git a/src/Actions/MapArguments.php b/src/Actions/MapArguments.php new file mode 100644 index 00000000..11886f46 --- /dev/null +++ b/src/Actions/MapArguments.php @@ -0,0 +1,102 @@ +handleArguments($_SERVER['argv']); + } + } + + private static function parallel(): void + { + if (self::unsetArgument('--parallel')) { + self::setArgument('--runner', Runner::class); + } + } + + private static function inParallel(TestSuite $testSuite): void + { + if (self::unsetArgument('--isInParallel')) { + $testSuite->isInParallel = true; + } + } + + private static function color(): void + { + $argv = new ArgvInput(); + $isDecorated = $argv->getParameterOption('--colors', 'always') !== 'never'; + + self::unsetArgument('--colors'); + //refactor later + self::unsetArgument('--colors=always'); + self::unsetArgument('--colors=auto'); + self::unsetArgument('--colors=never'); + + if ($isDecorated) { + self::setArgument('--colors'); + } + } + + private static function coverage(): void + { + if (! Coverage::isAvailable()) { + Container::getInstance()->get(OutputInterface::class)->writeln( + "\n ERROR No code coverage driver is available.", + ); + exit(1); + } + } + + private static function unsetArgument(string $argument): bool + { + if (($key = array_search($argument, $_SERVER['argv'])) !== false) { + unset($_SERVER['argv'][$key]); + + return true; + } + + return false; + } + + private static function setArgument(string $argument, string $value = null): void + { + $_SERVER['argv'][] = $argument; + + if ($value !== null) { + $_SERVER['argv'][] = $value; + } + } +} diff --git a/src/Console/Paratest/Runner.php b/src/Console/Paratest/Runner.php index 2a19e050..138b5e3b 100644 --- a/src/Console/Paratest/Runner.php +++ b/src/Console/Paratest/Runner.php @@ -14,6 +14,7 @@ use ParaTest\Runners\PHPUnit\ResultPrinter; use ParaTest\Runners\PHPUnit\RunnerInterface; use ParaTest\Runners\PHPUnit\SuiteLoader; use Pest\Factories\TestCaseFactory; +use Pest\Plugins\Coverage; use Pest\TestSuite; use PHPUnit\TextUI\TestRunner; use SebastianBergmann\Timer\Timer; @@ -227,6 +228,12 @@ final class Runner implements RunnerInterface $this->output->writeln( sprintf('done [%s]', $timer->stop()->asString()) ); + + if ($this->options->coveragePhp() && file_exists(\Pest\Support\Coverage::getPath())) { + $coveragePlugin = new Coverage($this->output); + $coveragePlugin->coverage = true; + $coveragePlugin->addOutput(0); + } } private function hasCoverage(): bool