mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
Fixes test name
This commit is contained in:
@ -4,18 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pest\Plugins\Parallel\Paratest;
|
||||
|
||||
use NunoMaduro\Collision\Adapters\Phpunit\TestResult as CollisionTestResult;
|
||||
use ParaTest\Options;
|
||||
use Pest\Plugins\Parallel\Support\CompactPrinter;
|
||||
use Pest\Support\StateGenerator;
|
||||
use PHPUnit\Event\Test\Errored;
|
||||
use PHPUnit\TestRunner\TestResult\TestResult;
|
||||
use PHPUnit\TextUI\Output\Printer;
|
||||
use SebastianBergmann\Timer\Duration;
|
||||
use SplFileInfo;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatter;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
use function assert;
|
||||
use function fclose;
|
||||
use function feof;
|
||||
@ -24,28 +12,40 @@ use function fread;
|
||||
use function fseek;
|
||||
use function ftell;
|
||||
use function fwrite;
|
||||
use ParaTest\Options;
|
||||
use Pest\Plugins\Parallel\Support\CompactPrinter;
|
||||
use Pest\Support\StateGenerator;
|
||||
use PHPUnit\TestRunner\TestResult\TestResult;
|
||||
use PHPUnit\TextUI\Output\Printer;
|
||||
use function preg_replace;
|
||||
use SebastianBergmann\Timer\Duration;
|
||||
use SplFileInfo;
|
||||
use function sprintf;
|
||||
use function strlen;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatter;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/** @internal */
|
||||
final class ResultPrinter
|
||||
{
|
||||
public readonly Printer $printer;
|
||||
|
||||
private readonly CompactPrinter $compactPrinter;
|
||||
|
||||
private int $totalCases = 0;
|
||||
private int $totalCases = 0;
|
||||
|
||||
/** @var resource|null */
|
||||
private $teamcityLogFileHandle;
|
||||
/** @var array<non-empty-string, int> */
|
||||
|
||||
/** @var array<string, int> */
|
||||
private array $tailPositions;
|
||||
|
||||
public function __construct(
|
||||
private readonly OutputInterface $output,
|
||||
private readonly Options $options
|
||||
) {
|
||||
$this->printer = new class ($this->output) implements Printer {
|
||||
$this->printer = new class($this->output) implements Printer
|
||||
{
|
||||
public function __construct(
|
||||
private readonly OutputInterface $output,
|
||||
) {
|
||||
@ -88,7 +88,7 @@ final class ResultPrinter
|
||||
);
|
||||
}
|
||||
|
||||
/** @param list<SplFileInfo> $teamcityFiles */
|
||||
/** @param array<int, SplFileInfo> $teamcityFiles */
|
||||
public function printFeedback(SplFileInfo $progressFile, array $teamcityFiles): void
|
||||
{
|
||||
if ($this->options->needsTeamcity) {
|
||||
@ -115,17 +115,17 @@ final class ResultPrinter
|
||||
return;
|
||||
}
|
||||
|
||||
$feedbackItems = preg_replace('/ +\\d+ \\/ \\d+ \\( ?\\d+%\\)\\s*/', '', $feedbackItems);
|
||||
$feedbackItems = (string) preg_replace('/ +\\d+ \\/ \\d+ \\( ?\\d+%\\)\\s*/', '', $feedbackItems);
|
||||
|
||||
$actualTestCount = strlen($feedbackItems);
|
||||
for ($index = 0; $index < $actualTestCount; ++$index) {
|
||||
for ($index = 0; $index < $actualTestCount; $index++) {
|
||||
$this->printFeedbackItem($feedbackItems[$index]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<SplFileInfo> $teamcityFiles
|
||||
* @param list<SplFileInfo> $testdoxFiles
|
||||
* @param array<int, SplFileInfo> $teamcityFiles
|
||||
* @param array<int, SplFileInfo> $testdoxFiles
|
||||
*/
|
||||
public function printResults(TestResult $testResult, array $teamcityFiles, array $testdoxFiles, Duration $duration): void
|
||||
{
|
||||
@ -134,7 +134,7 @@ final class ResultPrinter
|
||||
|
||||
if ($this->teamcityLogFileHandle !== null) {
|
||||
fwrite($this->teamcityLogFileHandle, $teamcityProgress);
|
||||
$resource = $this->teamcityLogFileHandle;
|
||||
$resource = $this->teamcityLogFileHandle;
|
||||
$this->teamcityLogFileHandle = null;
|
||||
fclose($resource);
|
||||
}
|
||||
@ -166,7 +166,7 @@ final class ResultPrinter
|
||||
$this->compactPrinter->descriptionItem($item);
|
||||
}
|
||||
|
||||
/** @param list<SplFileInfo> $files */
|
||||
/** @param array<int, SplFileInfo> $files */
|
||||
private function tailMultiple(array $files): string
|
||||
{
|
||||
$content = '';
|
||||
@ -183,7 +183,7 @@ final class ResultPrinter
|
||||
|
||||
private function tail(SplFileInfo $file): string
|
||||
{
|
||||
$path = $file->getPathname();
|
||||
$path = $file->getPathname();
|
||||
$handle = fopen($path, 'r');
|
||||
assert($handle !== false);
|
||||
$fseek = fseek($handle, $this->tailPositions[$path] ?? 0);
|
||||
|
||||
@ -4,43 +4,46 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pest\Plugins\Parallel\Support;
|
||||
|
||||
use NunoMaduro\Collision\Adapters\Phpunit\Printers\DefaultPrinter;
|
||||
use NunoMaduro\Collision\Adapters\Phpunit\State;
|
||||
use NunoMaduro\Collision\Adapters\Phpunit\Style;
|
||||
use NunoMaduro\Collision\Adapters\Phpunit\TestResult;
|
||||
use NunoMaduro\Collision\Exceptions\ShouldNotHappen;
|
||||
use Pest\Logging\TeamCity\Converter;
|
||||
use Pest\Support\StateGenerator;
|
||||
use PHPUnit\Event\Code\TestDox;
|
||||
use PHPUnit\Event\Code\TestMethod;
|
||||
use PHPUnit\Event\Event;
|
||||
use PHPUnit\Event\Telemetry\HRTime;
|
||||
use PHPUnit\Event\Telemetry\Info;
|
||||
use PHPUnit\Event\Telemetry\MemoryUsage;
|
||||
use PHPUnit\Event\Telemetry\Snapshot;
|
||||
use PHPUnit\Event\Test\Passed;
|
||||
use PHPUnit\Event\TestData\TestDataCollection;
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
use PHPUnit\Framework\IncompleteTestError;
|
||||
use PHPUnit\Metadata\MetadataCollection;
|
||||
use PHPUnit\TestRunner\TestResult\TestResult as PHPUnitTestResult;
|
||||
use ReflectionClass;
|
||||
use SebastianBergmann\Timer\Duration;
|
||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
use Symfony\Component\Console\Output\ConsoleOutputInterface;
|
||||
use Termwind\Terminal;
|
||||
use function Termwind\render;
|
||||
use function Termwind\renderUsing;
|
||||
use Termwind\Terminal;
|
||||
use function Termwind\terminal;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class CompactPrinter
|
||||
{
|
||||
private readonly Terminal $terminal;
|
||||
private readonly ConsoleOutputInterface $output;
|
||||
|
||||
private readonly Style $style;
|
||||
|
||||
private int $compactProcessed = 0;
|
||||
private int $compactSymbolsPerLine = 0;
|
||||
|
||||
private readonly int $compactSymbolsPerLine;
|
||||
|
||||
/**
|
||||
* @var array<string, array<int, string>>
|
||||
*/
|
||||
private const LOOKUP_TABLE = [
|
||||
'.' => ['gray', '.'],
|
||||
'S' => ['yellow', 's'],
|
||||
'I' => ['yellow', 'i'],
|
||||
'N' => ['yellow', 'i'],
|
||||
'R' => ['yellow', '!'],
|
||||
'W' => ['yellow', '!'],
|
||||
'E' => ['red', '⨯'],
|
||||
'F' => ['red', '⨯'],
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@ -51,32 +54,28 @@ final class CompactPrinter
|
||||
$this->compactSymbolsPerLine = $this->terminal->width() - 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output an empty line in the console. Useful for providing a little breathing room.
|
||||
*/
|
||||
public function newLine(): void
|
||||
{
|
||||
render('<div class="py-1"></div>');
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the given message to the console, adding vertical and horizontal padding.
|
||||
*/
|
||||
public function line(string $message): void
|
||||
{
|
||||
render("<span class='mx-2 py-1 text-gray'>{$message}</span>");
|
||||
render("<span class='mx-2 py-1 text-gray-700'>{$message}</span>");
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the given description item from the ProgressPrinter as a gorgeous, colored symbol.
|
||||
*/
|
||||
public function descriptionItem(string $item): void
|
||||
{
|
||||
// TODO: Support TODOs
|
||||
|
||||
$lookupTable = [
|
||||
'.' => ['gray', '.'],
|
||||
'S' => ['yellow', 's'],
|
||||
'I' => ['yellow', 'i'],
|
||||
'N' => ['yellow', 'i'],
|
||||
'R' => ['yellow', '!'],
|
||||
'W' => ['yellow', '!'],
|
||||
'E' => ['red', '⨯'],
|
||||
'F' => ['red', '⨯'],
|
||||
];
|
||||
|
||||
[$color, $icon] = $lookupTable[$item] ?? $lookupTable['.'];
|
||||
[$color, $icon] = self::LOOKUP_TABLE[$item] ?? self::LOOKUP_TABLE['.'];
|
||||
|
||||
$symbolsOnCurrentLine = $this->compactProcessed % $this->compactSymbolsPerLine;
|
||||
|
||||
@ -94,19 +93,24 @@ final class CompactPrinter
|
||||
$this->compactProcessed++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs all errors from the given state using Collision's beautiful error output.
|
||||
*/
|
||||
public function errors(State $state): void
|
||||
{
|
||||
$this->style->writeErrorsSummary($state, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a clean recap of the test run, including the number of tests, assertions, and failures.
|
||||
*/
|
||||
public function recap(State $state, PHPUnitTestResult $testResult, Duration $duration): void
|
||||
{
|
||||
assert($this->output instanceof ConsoleOutput);
|
||||
$style = new Style($this->output);
|
||||
|
||||
$nanoseconds = $duration->asNanoseconds() % 1000000000;
|
||||
$snapshotDuration = HRTime::fromSecondsAndNanoseconds((int)$duration->asSeconds(), $nanoseconds);
|
||||
$telemetryDuration = \PHPUnit\Event\Telemetry\Duration::fromSecondsAndNanoseconds((int)$duration->asSeconds(), $nanoseconds);
|
||||
$nanoseconds = $duration->asNanoseconds() % 1_000_000_000;
|
||||
$snapshotDuration = HRTime::fromSecondsAndNanoseconds((int) $duration->asSeconds(), $nanoseconds);
|
||||
$telemetryDuration = \PHPUnit\Event\Telemetry\Duration::fromSecondsAndNanoseconds((int) $duration->asSeconds(), $nanoseconds);
|
||||
|
||||
$telemetry = new Info(
|
||||
new Snapshot(
|
||||
@ -120,6 +124,6 @@ final class CompactPrinter
|
||||
MemoryUsage::fromBytes(0),
|
||||
);
|
||||
|
||||
$style->writeRecap($state, $telemetry, $testResult);
|
||||
$this->style->writeRecap($state, $telemetry, $testResult);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user