mirror of
https://github.com/pestphp/pest.git
synced 2026-03-12 18:57:22 +01:00
Output improvements.
This commit is contained in:
@ -22,11 +22,11 @@ use Throwable;
|
|||||||
|
|
||||||
final class TeamCity extends DefaultResultPrinter
|
final class TeamCity extends DefaultResultPrinter
|
||||||
{
|
{
|
||||||
private const PROTOCOL = 'pest_qn://';
|
private const PROTOCOL = 'pest_qn://';
|
||||||
private const NAME = 'name';
|
private const NAME = 'name';
|
||||||
private const LOCATION_HINT = 'locationHint';
|
private const LOCATION_HINT = 'locationHint';
|
||||||
private const DURATION = 'duration';
|
private const DURATION = 'duration';
|
||||||
private const TEST_SUITE_STARTED = 'testSuiteStarted';
|
private const TEST_SUITE_STARTED = 'testSuiteStarted';
|
||||||
private const TEST_SUITE_FINISHED = 'testSuiteFinished';
|
private const TEST_SUITE_FINISHED = 'testSuiteFinished';
|
||||||
|
|
||||||
/** @var int */
|
/** @var int */
|
||||||
@ -39,7 +39,7 @@ final class TeamCity extends DefaultResultPrinter
|
|||||||
private $phpunitTeamCity;
|
private $phpunitTeamCity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param resource|string|null $out
|
* @param resource|string|null $out
|
||||||
*/
|
*/
|
||||||
public function __construct($out, bool $verbose, string $colors)
|
public function __construct($out, bool $verbose, string $colors)
|
||||||
{
|
{
|
||||||
@ -59,7 +59,7 @@ final class TeamCity extends DefaultResultPrinter
|
|||||||
private function logo(): void
|
private function logo(): void
|
||||||
{
|
{
|
||||||
$this->writeNewLine();
|
$this->writeNewLine();
|
||||||
$this->write('Pest ' . version());
|
$this->write('Pest '.version());
|
||||||
$this->writeNewLine();
|
$this->writeNewLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,12 +74,12 @@ final class TeamCity extends DefaultResultPrinter
|
|||||||
$this->writeProgress('Tests: ');
|
$this->writeProgress('Tests: ');
|
||||||
|
|
||||||
$results = [
|
$results = [
|
||||||
'failed' => ['count' => $result->errorCount() + $result->failureCount(), 'color' => 'fg-red'],
|
'failed' => ['count' => $result->errorCount() + $result->failureCount(), 'color' => 'fg-red'],
|
||||||
'skipped' => ['count' => $result->skippedCount(), 'color' => 'fg-cyan'],
|
'skipped' => ['count' => $result->skippedCount(), 'color' => 'fg-cyan'],
|
||||||
'warned' => ['count' => $result->warningCount(), 'color' => 'fg-cyan'],
|
'warned' => ['count' => $result->warningCount(), 'color' => 'fg-cyan'],
|
||||||
'risked' => ['count' => $result->riskyCount(), 'color' => 'fg-cyan'],
|
'risked' => ['count' => $result->riskyCount(), 'color' => 'fg-cyan'],
|
||||||
'incomplete' => ['count' => $result->notImplementedCount(), 'color' => 'fg-cyan'],
|
'incomplete' => ['count' => $result->notImplementedCount(), 'color' => 'fg-cyan'],
|
||||||
'passed' => ['count' => $this->successfulTestCount($result), 'color' => 'fg-green'],
|
'passed' => ['count' => $this->successfulTestCount($result), 'color' => 'fg-green'],
|
||||||
];
|
];
|
||||||
|
|
||||||
$filteredResults = array_filter($results, function ($item): bool {
|
$filteredResults = array_filter($results, function ($item): bool {
|
||||||
@ -87,7 +87,7 @@ final class TeamCity extends DefaultResultPrinter
|
|||||||
});
|
});
|
||||||
|
|
||||||
foreach ($filteredResults as $key => $info) {
|
foreach ($filteredResults as $key => $info) {
|
||||||
$this->writeProgressWithColor($info['color'], $info['count'] . " $key");
|
$this->writeProgressWithColor($info['color'], $info['count']." $key");
|
||||||
|
|
||||||
if ($key !== array_reverse(array_keys($filteredResults))[0]) {
|
if ($key !== array_reverse(array_keys($filteredResults))[0]) {
|
||||||
$this->write(', ');
|
$this->write(', ');
|
||||||
@ -118,9 +118,7 @@ final class TeamCity extends DefaultResultPrinter
|
|||||||
public function startTestSuite(TestSuite $suite): void
|
public function startTestSuite(TestSuite $suite): void
|
||||||
{
|
{
|
||||||
if (static::isPestTestSuite($suite)) {
|
if (static::isPestTestSuite($suite)) {
|
||||||
$this->writeWithColor('fg-white, bold', ' ' . substr_replace($suite->getName(), '', 0, 2) . ' ');
|
$this->writeWithColor('fg-white, bold', ' '.substr_replace($suite->getName(), '', 0, 2).' ');
|
||||||
} else {
|
|
||||||
$this->writeWithColor('fg-white, bold', ' ' . $suite->getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->flowId = (int) getmypid();
|
$this->flowId = (int) getmypid();
|
||||||
@ -138,8 +136,8 @@ final class TeamCity extends DefaultResultPrinter
|
|||||||
if (file_exists($suiteName) || !method_exists($suiteName, '__getFileName')) {
|
if (file_exists($suiteName) || !method_exists($suiteName, '__getFileName')) {
|
||||||
$this->printEvent(
|
$this->printEvent(
|
||||||
self::TEST_SUITE_STARTED, [
|
self::TEST_SUITE_STARTED, [
|
||||||
self::NAME => $suiteName,
|
self::NAME => $suiteName,
|
||||||
self::LOCATION_HINT => self::PROTOCOL . $suiteName,
|
self::LOCATION_HINT => self::PROTOCOL.$suiteName,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -149,15 +147,15 @@ final class TeamCity extends DefaultResultPrinter
|
|||||||
|
|
||||||
$this->printEvent(
|
$this->printEvent(
|
||||||
self::TEST_SUITE_STARTED, [
|
self::TEST_SUITE_STARTED, [
|
||||||
self::NAME => substr($suiteName, 2),
|
self::NAME => substr($suiteName, 2),
|
||||||
self::LOCATION_HINT => self::PROTOCOL . $fileName,
|
self::LOCATION_HINT => self::PROTOCOL.$fileName,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify that the given test suite is a valid Pest suite.
|
* Verify that the given test suite is a valid Pest suite.
|
||||||
*
|
*
|
||||||
* @param TestSuite<Test> $suite
|
* @param TestSuite<Test> $suite
|
||||||
*/
|
*/
|
||||||
private static function isPestTestSuite(TestSuite $suite): bool
|
private static function isPestTestSuite(TestSuite $suite): bool
|
||||||
{
|
{
|
||||||
@ -165,7 +163,7 @@ final class TeamCity extends DefaultResultPrinter
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<string, string|int> $params
|
* @param array<string, string|int> $params
|
||||||
*/
|
*/
|
||||||
private function printEvent(string $eventName, array $params = []): void
|
private function printEvent(string $eventName, array $params = []): void
|
||||||
{
|
{
|
||||||
@ -196,16 +194,13 @@ final class TeamCity extends DefaultResultPrinter
|
|||||||
public function endTestSuite(TestSuite $suite): void
|
public function endTestSuite(TestSuite $suite): void
|
||||||
{
|
{
|
||||||
$suiteName = $suite->getName();
|
$suiteName = $suite->getName();
|
||||||
|
$this->writeNewLine();
|
||||||
if (static::isPestTestSuite($suite)) {
|
|
||||||
$this->writeNewLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (file_exists($suiteName) || !method_exists($suiteName, '__getFileName')) {
|
if (file_exists($suiteName) || !method_exists($suiteName, '__getFileName')) {
|
||||||
$this->printEvent(
|
$this->printEvent(
|
||||||
self::TEST_SUITE_FINISHED, [
|
self::TEST_SUITE_FINISHED, [
|
||||||
self::NAME => $suiteName,
|
self::NAME => $suiteName,
|
||||||
self::LOCATION_HINT => self::PROTOCOL . $suiteName,
|
self::LOCATION_HINT => self::PROTOCOL.$suiteName,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -215,12 +210,10 @@ final class TeamCity extends DefaultResultPrinter
|
|||||||
self::TEST_SUITE_FINISHED, [
|
self::TEST_SUITE_FINISHED, [
|
||||||
self::NAME => substr($suiteName, 2),
|
self::NAME => substr($suiteName, 2),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->writeNewLine();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Test|Testable $test
|
* @param Test|Testable $test
|
||||||
*/
|
*/
|
||||||
public function startTest(Test $test): void
|
public function startTest(Test $test): void
|
||||||
{
|
{
|
||||||
@ -233,7 +226,7 @@ final class TeamCity extends DefaultResultPrinter
|
|||||||
$this->printEvent('testStarted', [
|
$this->printEvent('testStarted', [
|
||||||
self::NAME => $test->getName(),
|
self::NAME => $test->getName(),
|
||||||
// @phpstan-ignore-next-line
|
// @phpstan-ignore-next-line
|
||||||
self::LOCATION_HINT => self::PROTOCOL . $test->toString(),
|
self::LOCATION_HINT => self::PROTOCOL.$test->toString(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,12 +239,12 @@ final class TeamCity extends DefaultResultPrinter
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Test|Testable $test
|
* @param Test|Testable $test
|
||||||
*/
|
*/
|
||||||
public function endTest(Test $test, float $time): void
|
public function endTest(Test $test, float $time): void
|
||||||
{
|
{
|
||||||
$this->printEvent('testFinished', [
|
$this->printEvent('testFinished', [
|
||||||
self::NAME => $test->getName(),
|
self::NAME => $test->getName(),
|
||||||
self::DURATION => self::toMilliseconds($time),
|
self::DURATION => self::toMilliseconds($time),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -268,6 +261,11 @@ final class TeamCity extends DefaultResultPrinter
|
|||||||
$this->lastTestFailed = false;
|
$this->lastTestFailed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function toMilliseconds(float $time): int
|
||||||
|
{
|
||||||
|
return (int) round($time * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
private function writePestTestOutput(string $message, string $color, string $symbol, string $suffix = null): void
|
private function writePestTestOutput(string $message, string $color, string $symbol, string $suffix = null): void
|
||||||
{
|
{
|
||||||
$this->writeProgressWithColor($color, "$symbol ");
|
$this->writeProgressWithColor($color, "$symbol ");
|
||||||
@ -279,13 +277,8 @@ final class TeamCity extends DefaultResultPrinter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function toMilliseconds(float $time): int
|
|
||||||
{
|
|
||||||
return (int) round($time * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Test|Testable $test
|
* @param Test|Testable $test
|
||||||
*/
|
*/
|
||||||
public function addError(Test $test, Throwable $t, float $time): void
|
public function addError(Test $test, Throwable $t, float $time): void
|
||||||
{
|
{
|
||||||
@ -306,7 +299,7 @@ final class TeamCity extends DefaultResultPrinter
|
|||||||
/**
|
/**
|
||||||
* @phpstan-ignore-next-line
|
* @phpstan-ignore-next-line
|
||||||
*
|
*
|
||||||
* @param Test|Testable $test
|
* @param Test|Testable $test
|
||||||
*/
|
*/
|
||||||
public function addWarning(Test $test, Warning $e, float $time): void
|
public function addWarning(Test $test, Warning $e, float $time): void
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user