mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
style(teamcity): fix styling
This commit is contained in:
@ -21,3 +21,12 @@ parameters:
|
|||||||
- "# with null as default value#"
|
- "# with null as default value#"
|
||||||
- "#has parameter \\$closure with default value.#"
|
- "#has parameter \\$closure with default value.#"
|
||||||
- "#has parameter \\$description with default value.#"
|
- "#has parameter \\$description with default value.#"
|
||||||
|
-
|
||||||
|
message: '#Call to an undefined method PHPUnit\\Framework\\Test::getName\(\)#'
|
||||||
|
path: src/TeamCity.php
|
||||||
|
-
|
||||||
|
message: '#invalid typehint type Pest\\Concerns\\TestCase#'
|
||||||
|
path: src/TeamCity.php
|
||||||
|
-
|
||||||
|
message: '#is not subtype of native type PHPUnit\\Framework\\Test#'
|
||||||
|
path: src/TeamCity.php
|
||||||
|
|||||||
@ -12,6 +12,11 @@ use Pest\TeamCity;
|
|||||||
*/
|
*/
|
||||||
final class AddsDefaults
|
final class AddsDefaults
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private const PRINTER = 'printer';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds default arguments to the given `arguments` array.
|
* Adds default arguments to the given `arguments` array.
|
||||||
*
|
*
|
||||||
@ -21,12 +26,12 @@ final class AddsDefaults
|
|||||||
*/
|
*/
|
||||||
public static function to(array $arguments): array
|
public static function to(array $arguments): array
|
||||||
{
|
{
|
||||||
if (!array_key_exists('printer', $arguments)) {
|
if (!array_key_exists(self::PRINTER, $arguments)) {
|
||||||
$arguments['printer'] = new Printer(null, $arguments['verbose'] ?? false, $arguments['colors'] ?? 'always');
|
$arguments[self::PRINTER] = new Printer(null, $arguments['verbose'] ?? false, $arguments['colors'] ?? 'always');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($arguments['printer'] === \PHPUnit\Util\Log\TeamCity::class) {
|
if ($arguments[self::PRINTER] === \PHPUnit\Util\Log\TeamCity::class) {
|
||||||
$arguments['printer'] = new TeamCity(null, $arguments['verbose'] ?? false, $arguments['colors'] ?? 'always');
|
$arguments[self::PRINTER] = new TeamCity(null, $arguments['verbose'] ?? false, $arguments['colors'] ?? 'always');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $arguments;
|
return $arguments;
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Pest;
|
namespace Pest;
|
||||||
|
|
||||||
use function getmypid;
|
use function getmypid;
|
||||||
@ -13,24 +15,32 @@ use PHPUnit\TextUI\DefaultResultPrinter;
|
|||||||
use function round;
|
use function round;
|
||||||
use function str_replace;
|
use function str_replace;
|
||||||
|
|
||||||
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 LOCATION_HINT = 'locationHint';
|
||||||
|
private const DURATION = 'duration';
|
||||||
|
|
||||||
|
/** @var int */
|
||||||
private $flowId;
|
private $flowId;
|
||||||
|
|
||||||
|
/** @var bool */
|
||||||
private $isSummaryTestCountPrinted = false;
|
private $isSummaryTestCountPrinted = false;
|
||||||
|
|
||||||
|
/** @var \PHPUnit\Util\Log\TeamCity */
|
||||||
private $phpunitTeamCity;
|
private $phpunitTeamCity;
|
||||||
|
|
||||||
public function __construct($out = null, bool $verbose = false, string $colors = self::COLOR_DEFAULT, bool $debug = false, $numberOfColumns = 80, bool $reverse = false)
|
public function __construct($out, bool $verbose, string $colors)
|
||||||
{
|
{
|
||||||
parent::__construct($out, $verbose, $colors, $debug, $numberOfColumns, $reverse);
|
parent::__construct($out, $verbose, $colors, false, 80, false);
|
||||||
$this->phpunitTeamCity = new \PHPUnit\Util\Log\TeamCity(
|
$this->phpunitTeamCity = new \PHPUnit\Util\Log\TeamCity(
|
||||||
$out,
|
$out,
|
||||||
$verbose,
|
$verbose,
|
||||||
$colors,
|
$colors,
|
||||||
$debug,
|
false,
|
||||||
$numberOfColumns,
|
80,
|
||||||
$reverse
|
false
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,6 +50,7 @@ class TeamCity extends DefaultResultPrinter
|
|||||||
$this->printFooter($result);
|
$this->printFooter($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @phpstan-ignore-next-line */
|
||||||
public function startTestSuite(TestSuite $suite): void
|
public function startTestSuite(TestSuite $suite): void
|
||||||
{
|
{
|
||||||
$this->flowId = getmypid();
|
$this->flowId = getmypid();
|
||||||
@ -56,8 +67,8 @@ class TeamCity extends DefaultResultPrinter
|
|||||||
|
|
||||||
if (file_exists($suiteName)) {
|
if (file_exists($suiteName)) {
|
||||||
$this->printEvent('testSuiteStarted', [
|
$this->printEvent('testSuiteStarted', [
|
||||||
'name' => $suiteName,
|
self::NAME => $suiteName,
|
||||||
'locationHint' => self::PROTOCOL . $suiteName,
|
self::LOCATION_HINT => self::PROTOCOL . $suiteName,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -66,26 +77,27 @@ class TeamCity extends DefaultResultPrinter
|
|||||||
$fileName = $suite->getName()::__getFileName();
|
$fileName = $suite->getName()::__getFileName();
|
||||||
|
|
||||||
$this->printEvent('testSuiteStarted', [
|
$this->printEvent('testSuiteStarted', [
|
||||||
'name' => substr($suiteName, 2),
|
self::NAME => substr($suiteName, 2),
|
||||||
'locationHint' => self::PROTOCOL . $fileName,
|
self::LOCATION_HINT => self::PROTOCOL . $fileName,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @phpstan-ignore-next-line */
|
||||||
public function endTestSuite(TestSuite $suite): void
|
public function endTestSuite(TestSuite $suite): void
|
||||||
{
|
{
|
||||||
$suiteName = $suite->getName();
|
$suiteName = $suite->getName();
|
||||||
|
|
||||||
if (file_exists($suiteName)) {
|
if (file_exists($suiteName)) {
|
||||||
$this->printEvent('testSuiteFinished', [
|
$this->printEvent('testSuiteFinished', [
|
||||||
'name' => $suiteName,
|
self::NAME => $suiteName,
|
||||||
'locationHint' => self::PROTOCOL . $suiteName,
|
self::LOCATION_HINT => self::PROTOCOL . $suiteName,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->printEvent('testSuiteFinished', [
|
$this->printEvent('testSuiteFinished', [
|
||||||
'name' => substr($suiteName, 2),
|
self::NAME => substr($suiteName, 2),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,8 +113,9 @@ class TeamCity extends DefaultResultPrinter
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->printEvent('testStarted', [
|
$this->printEvent('testStarted', [
|
||||||
'name' => $test->getName(),
|
self::NAME => $test->getName(),
|
||||||
'locationHint' => self::PROTOCOL . $test->toString(),
|
/* @phpstan-ignore-next-line */
|
||||||
|
self::LOCATION_HINT => self::PROTOCOL . $test->toString(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,8 +131,8 @@ class TeamCity extends DefaultResultPrinter
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->printEvent('testFinished', [
|
$this->printEvent('testFinished', [
|
||||||
'name' => $test->getName(),
|
self::NAME => $test->getName(),
|
||||||
'duration' => self::toMilliseconds($time),
|
self::DURATION => self::toMilliseconds($time),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,21 +141,38 @@ class TeamCity extends DefaultResultPrinter
|
|||||||
*/
|
*/
|
||||||
public function addError(Test $test, \Throwable $t, float $time): void
|
public function addError(Test $test, \Throwable $t, float $time): void
|
||||||
{
|
{
|
||||||
|
if (!TeamCity::isPestTest($test)) {
|
||||||
|
$this->phpunitTeamCity->addError($test, $t, $time);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$this->printEvent('testFailed', [
|
$this->printEvent('testFailed', [
|
||||||
'name' => $test->getName(),
|
self::NAME => $test->getName(),
|
||||||
'message' => $t->getMessage(),
|
'message' => $t->getMessage(),
|
||||||
'details' => $t->getTraceAsString(),
|
'details' => $t->getTraceAsString(),
|
||||||
'duration' => self::toMilliseconds($time),
|
self::DURATION => self::toMilliseconds($time),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @phpstan-ignore-next-line
|
||||||
|
*
|
||||||
|
* @param Test|TestCase $test
|
||||||
|
*/
|
||||||
public function addWarning(Test $test, Warning $e, float $time): void
|
public function addWarning(Test $test, Warning $e, float $time): void
|
||||||
{
|
{
|
||||||
|
if (!TeamCity::isPestTest($test)) {
|
||||||
|
$this->phpunitTeamCity->addWarning($test, $e, $time);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$this->printEvent('testFailed', [
|
$this->printEvent('testFailed', [
|
||||||
'name' => $test->getName(),
|
self::NAME => $test->getName(),
|
||||||
'message' => $e->getMessage(),
|
'message' => $e->getMessage(),
|
||||||
'details' => $e->getTraceAsString(),
|
'details' => $e->getTraceAsString(),
|
||||||
'duration' => self::toMilliseconds($time),
|
self::DURATION => self::toMilliseconds($time),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,11 +185,14 @@ class TeamCity extends DefaultResultPrinter
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, string|int> $params
|
||||||
|
*/
|
||||||
private function printEvent(string $eventName, array $params = []): void
|
private function printEvent(string $eventName, array $params = []): void
|
||||||
{
|
{
|
||||||
$this->write("\n##teamcity[{$eventName}");
|
$this->write("\n##teamcity[{$eventName}");
|
||||||
|
|
||||||
if ($this->flowId) {
|
if ($this->flowId !== 0) {
|
||||||
$params['flowId'] = $this->flowId;
|
$params['flowId'] = $this->flowId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,8 +218,8 @@ class TeamCity extends DefaultResultPrinter
|
|||||||
return (int) round($time * 1000);
|
return (int) round($time * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function isPestTest($test): bool
|
private static function isPestTest(Test $test): bool
|
||||||
{
|
{
|
||||||
return in_array(TestCase::class, class_uses($test));
|
return in_array(TestCase::class, class_uses($test), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user