mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
More work on output
This commit is contained in:
@ -6,6 +6,7 @@ namespace Pest\Logging;
|
|||||||
|
|
||||||
use function getmypid;
|
use function getmypid;
|
||||||
use Pest\Concerns\Testable;
|
use Pest\Concerns\Testable;
|
||||||
|
use function Pest\version;
|
||||||
use PHPUnit\Framework\AssertionFailedError;
|
use PHPUnit\Framework\AssertionFailedError;
|
||||||
use PHPUnit\Framework\Test;
|
use PHPUnit\Framework\Test;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
@ -36,6 +37,9 @@ final class TeamCity extends DefaultResultPrinter
|
|||||||
/** @var \PHPUnit\Util\Log\TeamCity */
|
/** @var \PHPUnit\Util\Log\TeamCity */
|
||||||
private $phpunitTeamCity;
|
private $phpunitTeamCity;
|
||||||
|
|
||||||
|
/** @var array<callable> */
|
||||||
|
protected $outputStack = [];
|
||||||
|
|
||||||
public function __construct(bool $verbose, string $colors)
|
public function __construct(bool $verbose, string $colors)
|
||||||
{
|
{
|
||||||
parent::__construct(null, $verbose, $colors, false, 80, false);
|
parent::__construct(null, $verbose, $colors, false, 80, false);
|
||||||
@ -47,6 +51,15 @@ final class TeamCity extends DefaultResultPrinter
|
|||||||
80,
|
80,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->logo();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function logo()
|
||||||
|
{
|
||||||
|
$this->writeNewLine();
|
||||||
|
$this->write('Pest ' . version());
|
||||||
|
$this->writeNewLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function printResult(TestResult $result): void
|
public function printResult(TestResult $result): void
|
||||||
@ -58,6 +71,10 @@ final class TeamCity extends DefaultResultPrinter
|
|||||||
/** @phpstan-ignore-next-line */
|
/** @phpstan-ignore-next-line */
|
||||||
public function startTestSuite(TestSuite $suite): void
|
public function startTestSuite(TestSuite $suite): void
|
||||||
{
|
{
|
||||||
|
if (!str_contains($suite->getName(), '.php')) {
|
||||||
|
$this->writeWithColor('bold', substr_replace($suite->getName(), '', 0, 2));
|
||||||
|
}
|
||||||
|
|
||||||
$this->flowId = (int) getmypid();
|
$this->flowId = (int) getmypid();
|
||||||
|
|
||||||
if (!$this->isSummaryTestCountPrinted) {
|
if (!$this->isSummaryTestCountPrinted) {
|
||||||
@ -176,7 +193,20 @@ final class TeamCity extends DefaultResultPrinter
|
|||||||
{
|
{
|
||||||
$this->lastTestFailed = true;
|
$this->lastTestFailed = true;
|
||||||
$this->writePestTestOutput($test->getName(), 'red', '⨯');
|
$this->writePestTestOutput($test->getName(), 'red', '⨯');
|
||||||
$this->phpunitTeamCity->addError($test, $t, $time);
|
|
||||||
|
$this->outputStack[] = function () use ($test, $t, $time) {
|
||||||
|
$this->phpunitTeamCity->addError($test, $t, $time);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addFailure(Test $test, AssertionFailedError $e, float $time): void
|
||||||
|
{
|
||||||
|
$this->lastTestFailed = true;
|
||||||
|
$this->writePestTestOutput($test->getName(), 'red', '⨯');
|
||||||
|
|
||||||
|
$this->outputStack[] = function () use ($test, $e, $time) {
|
||||||
|
$this->phpunitTeamCity->addFailure($test, $e, $time);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -189,34 +219,35 @@ 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
|
public function addIncompleteTest(Test $test, Throwable $t, float $time): void
|
||||||
{
|
{
|
||||||
$this->lastTestFailed = true;
|
$this->lastTestFailed = true;
|
||||||
$this->writePestTestOutput($test->getName(), 'yellow', '!', function() use ($t) {
|
$this->writePestTestOutput($test->getName(), 'yellow', '…', function () use ($t) {
|
||||||
$this->writeProgressWithColor('fg-yellow', ' -> ' . $t->getMessage());
|
$this->writeProgressWithColor('fg-yellow', ' -> ' . $t->getMessage());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addFailure(Test $test, AssertionFailedError $e, float $time): void
|
public function addRiskyTest(Test $test, Throwable $t, float $time): void
|
||||||
{
|
{
|
||||||
$this->lastTestFailed = true;
|
$this->lastTestFailed = true;
|
||||||
$this->writePestTestOutput($test->getName(), 'red', '⨯');
|
$this->writePestTestOutput($test->getName(), 'yellow', '!', function () use ($t) {
|
||||||
$this->phpunitTeamCity->addFailure($test, $e, $time);
|
$this->writeProgressWithColor('fg-yellow', ' -> ' . $t->getMessage());
|
||||||
}
|
});
|
||||||
|
|
||||||
protected function writeProgress(string $progress): void
|
|
||||||
{
|
|
||||||
parent::writeProgress($progress);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addSkippedTest(Test $test, Throwable $t, float $time): void
|
public function addSkippedTest(Test $test, Throwable $t, float $time): void
|
||||||
{
|
{
|
||||||
$this->lastTestFailed = true;
|
$this->lastTestFailed = true;
|
||||||
$this->writePestTestOutput($test->getName(), 'yellow', '-', function() use ($t) {
|
$this->writePestTestOutput($test->getName(), 'yellow', '-', function () use ($t) {
|
||||||
$this->writeProgressWithColor('fg-yellow', ' -> ' . $t->getMessage());
|
$this->writeProgressWithColor('fg-yellow', ' -> ' . $t->getMessage());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function writeProgress(string $progress): void
|
||||||
|
{
|
||||||
|
parent::writeProgress($progress);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<string, string|int> $params
|
* @param array<string, string|int> $params
|
||||||
*/
|
*/
|
||||||
@ -245,31 +276,42 @@ final class TeamCity extends DefaultResultPrinter
|
|||||||
- $result->warningCount();
|
- $result->warningCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function printHeader(TestResult $result): void
|
||||||
|
{
|
||||||
|
foreach ($this->outputStack as $callable) {
|
||||||
|
$callable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected function printFooter(TestResult $result): void
|
protected function printFooter(TestResult $result): void
|
||||||
{
|
{
|
||||||
|
$this->writeNewLine();
|
||||||
$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-yellow'],
|
'skipped' => ['count' => $result->skippedCount(), 'color' => 'fg-yellow'],
|
||||||
'warned' => ['count' => $result->warningCount(), 'color' => 'fg-yellow'],
|
'warned' => ['count' => $result->warningCount(), 'color' => 'fg-yellow'],
|
||||||
'risked' => ['count' => $result->riskyCount(), 'color' => 'fg-yellow'],
|
'risked' => ['count' => $result->riskyCount(), 'color' => 'fg-yellow'],
|
||||||
'incomplete' => ['count' => $result->notImplementedCount(), 'color' => 'fg-yellow'],
|
'incomplete' => ['count' => $result->notImplementedCount(), 'color' => 'fg-yellow'],
|
||||||
'passed' => ['count' => $this->countSuccessfulTests($result), 'color' => 'fg-green'],
|
'passed' => ['count' => $this->countSuccessfulTests($result), 'color' => 'fg-green'],
|
||||||
];
|
];
|
||||||
|
|
||||||
$filteredResults = array_filter($results, function($item) {
|
$filteredResults = array_filter($results, function ($item) {
|
||||||
return $item['count'] > 0;
|
return $item['count'] > 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
foreach ($filteredResults as $key => $result) {
|
foreach ($filteredResults as $key => $info) {
|
||||||
$this->writeProgressWithColor($result['color'], $result['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(', ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->writeNewLine();
|
||||||
|
$this->write("Time: {$result->time()}s");
|
||||||
|
|
||||||
$this->writeNewLine();
|
$this->writeNewLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -9,6 +9,11 @@ test('it properly parses json string', function () {
|
|||||||
->toBe('uno');
|
->toBe('uno');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('is incomplete');
|
||||||
|
|
||||||
|
it('doesnt do anything', function () {
|
||||||
|
});
|
||||||
|
|
||||||
test('fails with broken json string', function () {
|
test('fails with broken json string', function () {
|
||||||
expect('{":"Nuno"}')->json();
|
expect('{":"Nuno"}')->json();
|
||||||
})->throws(ExpectationFailedException::class);
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|||||||
Reference in New Issue
Block a user