Fixes test name

This commit is contained in:
Nuno Maduro
2023-02-07 00:55:48 +00:00
parent 1658176fe1
commit f48ae48677
2 changed files with 65 additions and 61 deletions

View File

@ -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);
}
}