mirror of
https://github.com/pestphp/pest.git
synced 2026-03-11 02:07:23 +01:00
Fixes and improvements.
This commit is contained in:
committed by
Nuno Maduro
parent
7466667c08
commit
2f519261f5
@ -5,28 +5,20 @@ declare(strict_types=1);
|
||||
namespace Pest\Plugins\Parallel\Paratest;
|
||||
|
||||
use NunoMaduro\Collision\Adapters\Phpunit\TestResult as CollisionTestResult;
|
||||
use NunoMaduro\Collision\Exceptions\TestException;
|
||||
use ParaTest\Options;
|
||||
use Pest\Plugins\Parallel\Support\CompactPrinter;
|
||||
use PHPUnit\Runner\TestSuiteSorter;
|
||||
use Pest\Support\StateGenerator;
|
||||
use PHPUnit\Event\Test\Errored;
|
||||
use PHPUnit\TestRunner\TestResult\TestResult;
|
||||
use PHPUnit\TextUI\Output\Default\ResultPrinter as DefaultResultPrinter;
|
||||
use PHPUnit\TextUI\Output\Printer;
|
||||
use PHPUnit\TextUI\Output\SummaryPrinter;
|
||||
use PHPUnit\Util\Color;
|
||||
use SebastianBergmann\CodeCoverage\Driver\Selector;
|
||||
use SebastianBergmann\CodeCoverage\Filter;
|
||||
use SebastianBergmann\Timer\Duration;
|
||||
use SebastianBergmann\Timer\ResourceUsageFormatter;
|
||||
use SplFileInfo;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatter;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
use Termwind\Terminal;
|
||||
use function assert;
|
||||
use function fclose;
|
||||
use function feof;
|
||||
use function floor;
|
||||
use function fopen;
|
||||
use function fread;
|
||||
use function fseek;
|
||||
@ -34,26 +26,16 @@ use function ftell;
|
||||
use function fwrite;
|
||||
use function preg_replace;
|
||||
use function sprintf;
|
||||
use function str_repeat;
|
||||
use function strlen;
|
||||
|
||||
use function Termwind\terminal;
|
||||
use const DIRECTORY_SEPARATOR;
|
||||
use const PHP_EOL;
|
||||
use const PHP_VERSION;
|
||||
|
||||
/** @internal */
|
||||
final class ResultPrinter
|
||||
{
|
||||
public readonly Printer $printer;
|
||||
private readonly CompactPrinter $compactPrinter;
|
||||
|
||||
private int $numTestsWidth = 0;
|
||||
private int $maxColumn = 0;
|
||||
private int $totalCases = 0;
|
||||
private int $column = 0;
|
||||
private int $casesProcessed = 0;
|
||||
private int $numberOfColumns = 80;
|
||||
|
||||
/** @var resource|null */
|
||||
private $teamcityLogFileHandle;
|
||||
/** @var array<non-empty-string, int> */
|
||||
@ -98,7 +80,7 @@ final class ResultPrinter
|
||||
public function start(): void
|
||||
{
|
||||
$this->compactPrinter->line(sprintf(
|
||||
'Running %d test file%s using %d process%s',
|
||||
'Running %d test%s using %d process%s',
|
||||
$this->totalCases,
|
||||
$this->totalCases === 1 ? '' : 's',
|
||||
$this->options->processes,
|
||||
@ -173,14 +155,10 @@ final class ResultPrinter
|
||||
|
||||
$this->compactPrinter->newLine();
|
||||
|
||||
$issues = array_map(fn($event) => CollisionTestResult::fromTestCase(
|
||||
$event->test(),
|
||||
CollisionTestResult::FAIL,
|
||||
$event->throwable(),
|
||||
), [...$testResult->testFailedEvents(), ...$testResult->testErroredEvents()]);
|
||||
$state = (new StateGenerator())->fromPhpUnitTestResult($testResult);
|
||||
|
||||
$this->compactPrinter->errors($issues);
|
||||
$this->compactPrinter->recap($testResult, $duration);
|
||||
$this->compactPrinter->errors($state);
|
||||
$this->compactPrinter->recap($state, $testResult, $duration);
|
||||
}
|
||||
|
||||
private function printFeedbackItem(string $item): void
|
||||
|
||||
@ -16,6 +16,7 @@ use PHPUnit\Event\Facade as EventFacade;
|
||||
use PHPUnit\Runner\CodeCoverage;
|
||||
use PHPUnit\TestRunner\TestResult\Facade as TestResultFacade;
|
||||
use PHPUnit\TestRunner\TestResult\TestResult;
|
||||
use PHPUnit\TextUI\Configuration\CodeCoverageFilterRegistry;
|
||||
use PHPUnit\TextUI\ShellExitCodeCalculator;
|
||||
use PHPUnit\Util\ExcludeList;
|
||||
use SebastianBergmann\Timer\Timer;
|
||||
@ -67,6 +68,8 @@ final class WrapperRunner implements RunnerInterface
|
||||
/** @var non-empty-string[] */
|
||||
private readonly array $parameters;
|
||||
|
||||
private CodeCoverageFilterRegistry $codeCoverageFilterRegistry;
|
||||
|
||||
public function __construct(
|
||||
private readonly Options $options,
|
||||
private readonly OutputInterface $output
|
||||
@ -92,6 +95,7 @@ final class WrapperRunner implements RunnerInterface
|
||||
$parameters[] = $wrapper;
|
||||
|
||||
$this->parameters = $parameters;
|
||||
$this->codeCoverageFilterRegistry = new CodeCoverageFilterRegistry();
|
||||
}
|
||||
|
||||
public function run(): int
|
||||
@ -99,7 +103,7 @@ final class WrapperRunner implements RunnerInterface
|
||||
ExcludeList::addDirectory(dirname(__DIR__));
|
||||
TestResultFacade::init();
|
||||
EventFacade::seal();
|
||||
$suiteLoader = new SuiteLoader($this->options, $this->output);
|
||||
$suiteLoader = new SuiteLoader($this->options, $this->output, $this->codeCoverageFilterRegistry,);
|
||||
$this->pending = $this->getTestFiles($suiteLoader);
|
||||
|
||||
$result = TestResultFacade::result();
|
||||
@ -116,11 +120,6 @@ final class WrapperRunner implements RunnerInterface
|
||||
return $this->complete($result);
|
||||
}
|
||||
|
||||
public function getExitCode(): int
|
||||
{
|
||||
return $this->exitcode;
|
||||
}
|
||||
|
||||
private function startWorkers(): void
|
||||
{
|
||||
for ($token = 1; $token <= $this->options->processes; ++$token) {
|
||||
@ -155,6 +154,8 @@ final class WrapperRunner implements RunnerInterface
|
||||
) {
|
||||
$this->pending = [];
|
||||
} elseif (($pending = array_shift($this->pending)) !== null) {
|
||||
$this->debug(sprintf('Assigning %s to worker %d', $pending, $token));
|
||||
|
||||
$worker->assign($pending);
|
||||
$this->batches[$token]++;
|
||||
}
|
||||
@ -312,13 +313,14 @@ final class WrapperRunner implements RunnerInterface
|
||||
return;
|
||||
}
|
||||
|
||||
CodeCoverage::init($this->options->configuration);
|
||||
$coverageMerger = new CoverageMerger(CodeCoverage::instance());
|
||||
$coverageManager = new CodeCoverage();
|
||||
$coverageManager->init($this->options->configuration, $this->codeCoverageFilterRegistry);
|
||||
$coverageMerger = new CoverageMerger($coverageManager->codeCoverage());
|
||||
foreach ($this->coverageFiles as $coverageFile) {
|
||||
$coverageMerger->addCoverageFromFile($coverageFile);
|
||||
}
|
||||
|
||||
CodeCoverage::generateReports(
|
||||
$coverageManager->generateReports(
|
||||
$this->printer->printer,
|
||||
$this->options->configuration,
|
||||
);
|
||||
@ -349,14 +351,13 @@ final class WrapperRunner implements RunnerInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* We are doing this because the SuiteLoader returns filenames incorrectly
|
||||
* for Pest tests. Ideally we should find a cleaner solution.
|
||||
*/
|
||||
private function getTestFiles(SuiteLoader $suiteLoader): array
|
||||
{
|
||||
/**
|
||||
* TODO: Clean this up
|
||||
*
|
||||
* We are doing this because the SuiteLoader returns filenames incorrectly
|
||||
* for Pest tests. We need to find a better way to do this.
|
||||
*/
|
||||
$this->debug(sprintf("Found %d test file%s", count($suiteLoader->files), count($suiteLoader->files) === 1 ? '' : 's'));
|
||||
|
||||
$tests = array_filter(
|
||||
$suiteLoader->files,
|
||||
@ -365,4 +366,11 @@ final class WrapperRunner implements RunnerInterface
|
||||
|
||||
return [...$tests, ...TestSuite::getInstance()->tests->getFilenames()];
|
||||
}
|
||||
|
||||
private function debug(string $message): void
|
||||
{
|
||||
if ($this->options->verbose) {
|
||||
$this->output->writeln(" <fg=blue>{$message}</> ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user