refactor(teamcity): Small cleanup

This commit is contained in:
Oliver Nybroe
2020-07-28 11:04:08 +02:00
parent fa413aafbb
commit 0c16942d37
2 changed files with 25 additions and 18 deletions

View File

@ -6,15 +6,13 @@ namespace Pest\Actions;
use NunoMaduro\Collision\Adapters\Phpunit\Printer;
use Pest\TeamCity;
use PHPUnit\TextUI\DefaultResultPrinter;
/**
* @internal
*/
final class AddsDefaults
{
/**
* @var string
*/
private const PRINTER = 'printer';
/**
@ -27,11 +25,11 @@ final class AddsDefaults
public static function to(array $arguments): array
{
if (!array_key_exists(self::PRINTER, $arguments)) {
$arguments[self::PRINTER] = new Printer(null, $arguments['verbose'] ?? false, $arguments['colors'] ?? 'always');
$arguments[self::PRINTER] = new Printer(null, $arguments['verbose'] ?? false, $arguments['colors'] ?? DefaultResultPrinter::COLOR_ALWAYS);
}
if ($arguments[self::PRINTER] === \PHPUnit\Util\Log\TeamCity::class) {
$arguments[self::PRINTER] = new TeamCity(null, $arguments['verbose'] ?? false, $arguments['colors'] ?? 'always');
$arguments[self::PRINTER] = new TeamCity($arguments['verbose'] ?? false, $arguments['colors'] ?? DefaultResultPrinter::COLOR_ALWAYS);
}
return $arguments;

View File

@ -17,10 +17,13 @@ use function str_replace;
final class TeamCity extends DefaultResultPrinter
{
private const PROTOCOL = 'pest_qn://';
private const NAME = 'name';
private const LOCATION_HINT = 'locationHint';
private const DURATION = 'duration';
private const PROTOCOL = 'pest_qn://';
private const NAME = 'name';
private const LOCATION_HINT = 'locationHint';
private const DURATION = 'duration';
private const TEST_SUITE_STARTED = 'testSuiteStarted';
private const TEST_SUITE_FINISHED = 'testSuiteFinished';
private const TEST_FAILED = 'testFailed';
/** @var int */
private $flowId;
@ -31,11 +34,11 @@ final class TeamCity extends DefaultResultPrinter
/** @var \PHPUnit\Util\Log\TeamCity */
private $phpunitTeamCity;
public function __construct($out, bool $verbose, string $colors)
public function __construct(bool $verbose, string $colors)
{
parent::__construct($out, $verbose, $colors, false, 80, false);
parent::__construct(null, $verbose, $colors, false, 80, false);
$this->phpunitTeamCity = new \PHPUnit\Util\Log\TeamCity(
$out,
null,
$verbose,
$colors,
false,
@ -66,7 +69,8 @@ final class TeamCity extends DefaultResultPrinter
$suiteName = $suite->getName();
if (file_exists($suiteName)) {
$this->printEvent('testSuiteStarted', [
$this->printEvent(
self::TEST_SUITE_STARTED, [
self::NAME => $suiteName,
self::LOCATION_HINT => self::PROTOCOL . $suiteName,
]);
@ -76,7 +80,8 @@ final class TeamCity extends DefaultResultPrinter
$fileName = $suite->getName()::__getFileName();
$this->printEvent('testSuiteStarted', [
$this->printEvent(
self::TEST_SUITE_STARTED, [
self::NAME => substr($suiteName, 2),
self::LOCATION_HINT => self::PROTOCOL . $fileName,
]);
@ -88,7 +93,8 @@ final class TeamCity extends DefaultResultPrinter
$suiteName = $suite->getName();
if (file_exists($suiteName)) {
$this->printEvent('testSuiteFinished', [
$this->printEvent(
self::TEST_SUITE_FINISHED, [
self::NAME => $suiteName,
self::LOCATION_HINT => self::PROTOCOL . $suiteName,
]);
@ -96,7 +102,8 @@ final class TeamCity extends DefaultResultPrinter
return;
}
$this->printEvent('testSuiteFinished', [
$this->printEvent(
self::TEST_SUITE_FINISHED, [
self::NAME => substr($suiteName, 2),
]);
}
@ -147,7 +154,8 @@ final class TeamCity extends DefaultResultPrinter
return;
}
$this->printEvent('testFailed', [
$this->printEvent(
self::TEST_FAILED, [
self::NAME => $test->getName(),
'message' => $t->getMessage(),
'details' => $t->getTraceAsString(),
@ -168,7 +176,8 @@ final class TeamCity extends DefaultResultPrinter
return;
}
$this->printEvent('testFailed', [
$this->printEvent(
self::TEST_FAILED, [
self::NAME => $test->getName(),
'message' => $e->getMessage(),
'details' => $e->getTraceAsString(),