testSuite = $testSuite; $this->output = $output; } /** * {@inheritdoc} * * @phpstan-ignore-next-line * * @param array $argv */ protected function handleArguments(array $argv): void { /* * First, let's handle pest is own `--coverage` param. */ $argv = AddsCoverage::from($this->testSuite, $argv); /* * Next, as usual, let's send the console arguments to PHPUnit. */ parent::handleArguments($argv); /* * Finally, let's validate the configuration. Making * sure all options are yet supported by Pest. */ ValidatesConfiguration::in($this->arguments); } /** * Creates a new PHPUnit test runner. */ protected function createRunner(): TestRunner { /* * First, let's add the defaults we use on `pest`. Those * are the printer class, and others that may be appear. */ $this->arguments = AddsDefaults::to($this->arguments); $testRunner = new TestRunner($this->arguments['loader']); $testSuite = $this->arguments['test']; if (is_string($testSuite)) { if (\is_dir($testSuite)) { /** @var string[] $files */ $files = (new FileIteratorFacade())->getFilesAsArray( $testSuite, $this->arguments['testSuffixes'] ); } else { $files = [$testSuite]; } $testSuite = new BaseTestSuite($testSuite); $testSuite->addTestFiles($files); $this->arguments['test'] = $testSuite; } LoadStructure::in($this->testSuite->rootPath); AddsTests::to($testSuite, $this->testSuite); return $testRunner; } /** * {@inheritdoc} * * @phpstan-ignore-next-line * * @param array $argv */ public function run(array $argv, bool $exit = true): int { $result = parent::run($argv, false); if ($result === 0 && $this->testSuite->coverage) { if (!Coverage::isAvailable()) { throw new CodeCoverageDriverNotAvailable(); } $coverage = Coverage::report($this->output); $result = (int) ($coverage < $this->testSuite->coverageMin); if ($result === 1) { $this->output->writeln(sprintf( "\n FAIL Code coverage below expected: %s %%. Minimum: %s %%.", number_format($coverage, 1), number_format($this->testSuite->coverageMin, 1) )); } } exit($result); } }