mirror of
https://github.com/pestphp/pest.git
synced 2026-03-12 02:37:22 +01:00
Start of work on better TeamCity output
This commit is contained in:
@ -139,23 +139,43 @@ final class TeamCity extends DefaultResultPrinter
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$this->lastTestFailed) {
|
||||||
|
$this->writePestTestOutput($test->getName(), 'green', '✓');
|
||||||
|
}
|
||||||
|
|
||||||
if ($test instanceof TestCase) {
|
if ($test instanceof TestCase) {
|
||||||
$this->numAssertions += $test->getNumAssertions();
|
$this->numAssertions += $test->getNumAssertions();
|
||||||
} elseif ($test instanceof PhptTestCase) {
|
} elseif ($test instanceof PhptTestCase) {
|
||||||
$this->numAssertions++;
|
$this->numAssertions++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->lastTestFailed = false;
|
||||||
|
|
||||||
$this->printEvent('testFinished', [
|
$this->printEvent('testFinished', [
|
||||||
self::NAME => $test->getName(),
|
self::NAME => $test->getName(),
|
||||||
self::DURATION => self::toMilliseconds($time),
|
self::DURATION => self::toMilliseconds($time),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function writePestTestOutput(string $message, string $color, string $symbol, callable $suffix = null)
|
||||||
|
{
|
||||||
|
$this->writeProgressWithColor("fg-$color, bold", "$symbol ");
|
||||||
|
$this->writeProgress($message);
|
||||||
|
|
||||||
|
if ($suffix) {
|
||||||
|
$suffix();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->writeNewLine();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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
|
||||||
{
|
{
|
||||||
|
$this->lastTestFailed = true;
|
||||||
|
$this->writePestTestOutput($test->getName(), 'red', '⨯');
|
||||||
$this->phpunitTeamCity->addError($test, $t, $time);
|
$this->phpunitTeamCity->addError($test, $t, $time);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,13 +189,32 @@ final class TeamCity extends DefaultResultPrinter
|
|||||||
$this->phpunitTeamCity->addWarning($test, $e, $time);
|
$this->phpunitTeamCity->addWarning($test, $e, $time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addRiskyTest(Test $test, Throwable $t, float $time): void
|
||||||
|
{
|
||||||
|
$this->lastTestFailed = true;
|
||||||
|
$this->writePestTestOutput($test->getName(), 'yellow', '!', function() use ($t) {
|
||||||
|
$this->writeProgressWithColor('fg-yellow', ' -> ' . $t->getMessage());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public function addFailure(Test $test, AssertionFailedError $e, float $time): void
|
public function addFailure(Test $test, AssertionFailedError $e, float $time): void
|
||||||
{
|
{
|
||||||
|
$this->lastTestFailed = true;
|
||||||
|
$this->writePestTestOutput($test->getName(), 'red', '⨯');
|
||||||
$this->phpunitTeamCity->addFailure($test, $e, $time);
|
$this->phpunitTeamCity->addFailure($test, $e, $time);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function writeProgress(string $progress): void
|
protected function writeProgress(string $progress): void
|
||||||
{
|
{
|
||||||
|
parent::writeProgress($progress);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addSkippedTest(Test $test, Throwable $t, float $time): void
|
||||||
|
{
|
||||||
|
$this->lastTestFailed = true;
|
||||||
|
$this->writePestTestOutput($test->getName(), 'yellow', '-', function() use ($t) {
|
||||||
|
$this->writeProgressWithColor('fg-yellow', ' -> ' . $t->getMessage());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -197,6 +236,43 @@ final class TeamCity extends DefaultResultPrinter
|
|||||||
$this->write("]\n");
|
$this->write("]\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function countSuccessfulTests(TestResult $result)
|
||||||
|
{
|
||||||
|
return $result->count()
|
||||||
|
- $result->failureCount()
|
||||||
|
- $result->errorCount()
|
||||||
|
- $result->skippedCount()
|
||||||
|
- $result->warningCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function printFooter(TestResult $result): void
|
||||||
|
{
|
||||||
|
$this->writeProgress('Tests: ');
|
||||||
|
|
||||||
|
$results = [
|
||||||
|
'failed' => ['count' => $result->errorCount() + $result->failureCount(), 'color' => 'fg-red'],
|
||||||
|
'skipped' => ['count' => $result->skippedCount(), 'color' => 'fg-yellow'],
|
||||||
|
'warned' => ['count' => $result->warningCount(), 'color' => 'fg-yellow'],
|
||||||
|
'risked' => ['count' => $result->riskyCount(), 'color' => 'fg-yellow'],
|
||||||
|
'incomplete' => ['count' => $result->notImplementedCount(), 'color' => 'fg-yellow'],
|
||||||
|
'passed' => ['count' => $this->countSuccessfulTests($result), 'color' => 'fg-green'],
|
||||||
|
];
|
||||||
|
|
||||||
|
$filteredResults = array_filter($results, function($item) {
|
||||||
|
return $item['count'] > 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
foreach ($filteredResults as $key => $result) {
|
||||||
|
$this->writeProgressWithColor($result['color'], $result['count'] . " $key");
|
||||||
|
|
||||||
|
if ($key !== array_reverse(array_keys($filteredResults))[0]) {
|
||||||
|
$this->write(', ');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->writeNewLine();
|
||||||
|
}
|
||||||
|
|
||||||
private static function escapeValue(string $text): string
|
private static function escapeValue(string $text): string
|
||||||
{
|
{
|
||||||
return str_replace(
|
return str_replace(
|
||||||
|
|||||||
@ -6,7 +6,7 @@ test('it properly parses json string', function () {
|
|||||||
expect('{"name":"Nuno"}')
|
expect('{"name":"Nuno"}')
|
||||||
->json()
|
->json()
|
||||||
->name
|
->name
|
||||||
->toBe('Nuno');
|
->toBe('uno');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('fails with broken json string', function () {
|
test('fails with broken json string', function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user