mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
fix: missing things on junit
This commit is contained in:
@ -107,7 +107,8 @@
|
||||
"Pest\\Plugins\\Snapshot",
|
||||
"Pest\\Plugins\\Verbose",
|
||||
"Pest\\Plugins\\Version",
|
||||
"Pest\\Plugins\\Parallel"
|
||||
"Pest\\Plugins\\Parallel",
|
||||
"Pest\\Plugins\\JUnit"
|
||||
]
|
||||
},
|
||||
"phpstan": {
|
||||
|
||||
@ -16,7 +16,6 @@ use Pest\Logging\JUnit\Subscriber\TestRunnerExecutionFinishedSubscriber;
|
||||
use Pest\Logging\JUnit\Subscriber\TestSkippedSubscriber;
|
||||
use Pest\Logging\JUnit\Subscriber\TestSuiteFinishedSubscriber;
|
||||
use Pest\Logging\JUnit\Subscriber\TestSuiteStartedSubscriber;
|
||||
use PHPUnit\Event\Code\TestMethod;
|
||||
use PHPUnit\Event\EventFacadeIsSealedException;
|
||||
use PHPUnit\Event\Facade;
|
||||
use PHPUnit\Event\InvalidArgumentException;
|
||||
@ -33,14 +32,12 @@ use PHPUnit\Event\TestSuite\Started;
|
||||
use PHPUnit\Event\UnknownSubscriberTypeException;
|
||||
use PHPUnit\TextUI\Output\Printer;
|
||||
use PHPUnit\Util\Xml;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class JUnitLogger
|
||||
{
|
||||
|
||||
private DOMDocument $document;
|
||||
|
||||
private DOMElement $root;
|
||||
@ -76,7 +73,7 @@ final class JUnitLogger
|
||||
private array $testSuiteSkipped = [0];
|
||||
|
||||
/**
|
||||
* @psalm-var array<int,int>
|
||||
* @psalm-var array<int,int|float>
|
||||
*/
|
||||
private array $testSuiteTimes = [0];
|
||||
|
||||
@ -94,7 +91,6 @@ final class JUnitLogger
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly Printer $printer,
|
||||
private readonly OutputInterface $output,
|
||||
private readonly Converter $converter,
|
||||
) {
|
||||
$this->registerSubscribers();
|
||||
@ -103,7 +99,7 @@ final class JUnitLogger
|
||||
|
||||
public function flush(): void
|
||||
{
|
||||
$this->printer->print($this->document->saveXML());
|
||||
$this->printer->print((string) $this->document->saveXML());
|
||||
|
||||
$this->printer->flush();
|
||||
}
|
||||
@ -240,8 +236,8 @@ final class JUnitLogger
|
||||
*/
|
||||
private function handleFinish(Info $telemetryInfo, int $numberOfAssertionsPerformed): void
|
||||
{
|
||||
assert($this->currentTestCase !== null);
|
||||
assert($this->time !== null);
|
||||
assert($this->currentTestCase instanceof \DOMElement);
|
||||
assert($this->time instanceof \PHPUnit\Event\Telemetry\HRTime);
|
||||
|
||||
$time = $telemetryInfo->time()->duration($this->time)->asFloat();
|
||||
|
||||
@ -292,8 +288,6 @@ final class JUnitLogger
|
||||
|
||||
private function createDocument(): void
|
||||
{
|
||||
$this->output->writeln('Start Junit');
|
||||
|
||||
$this->document = new DOMDocument('1.0', 'UTF-8');
|
||||
$this->document->formatOutput = true;
|
||||
|
||||
@ -311,7 +305,7 @@ final class JUnitLogger
|
||||
$this->createTestCase($event);
|
||||
}
|
||||
|
||||
assert($this->currentTestCase !== null);
|
||||
assert($this->currentTestCase instanceof \DOMElement);
|
||||
|
||||
$throwable = $event->throwable();
|
||||
|
||||
@ -349,7 +343,7 @@ final class JUnitLogger
|
||||
$this->createTestCase($event);
|
||||
}
|
||||
|
||||
assert($this->currentTestCase !== null);
|
||||
assert($this->currentTestCase instanceof \DOMElement);
|
||||
|
||||
$skipped = $this->document->createElement('skipped');
|
||||
|
||||
@ -379,8 +373,6 @@ final class JUnitLogger
|
||||
$testCase->setAttribute('file', $file);
|
||||
|
||||
if ($test->isTestMethod()) {
|
||||
assert($test instanceof TestMethod);
|
||||
|
||||
$className = $this->converter->getTrimmedTestClassName($test);
|
||||
$testCase->setAttribute('class', $className);
|
||||
$testCase->setAttribute('classname', str_replace('\\', '.', $className));
|
||||
|
||||
@ -320,7 +320,7 @@ final class Expectation
|
||||
public function toHaveProperties(iterable $names, string $message = ''): self
|
||||
{
|
||||
foreach ($names as $name => $value) {
|
||||
is_int($name) ? $this->toHaveProperty($value, message: $message) : $this->toHaveProperty($name, $value, $message);
|
||||
is_int($name) ? $this->toHaveProperty($value, message: $message) : $this->toHaveProperty($name, $value, $message); // @phpstan-ignore-line
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
||||
@ -31,10 +31,9 @@ final class Cache implements HandlesArguments
|
||||
public function handleArguments(array $arguments): array
|
||||
{
|
||||
if (! $this->hasArgument('--cache-directory', $arguments)) {
|
||||
$arguments = $this->pushArgument(
|
||||
sprintf('--cache-directory=%s', realpath(self::TEMPORARY_FOLDER)),
|
||||
$arguments
|
||||
);
|
||||
$arguments = $this->pushArgument('--cache-directory', $arguments);
|
||||
|
||||
$arguments = $this->pushArgument((string) realpath(self::TEMPORARY_FOLDER), $arguments);
|
||||
}
|
||||
|
||||
if (! $this->hasArgument('--parallel', $arguments)) {
|
||||
|
||||
44
src/Plugins/JUnit.php
Normal file
44
src/Plugins/JUnit.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Plugins;
|
||||
|
||||
use Pest\Contracts\Plugins\HandlesArguments;
|
||||
use Pest\Plugins\Concerns\HandleArguments;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class JUnit implements HandlesArguments
|
||||
{
|
||||
use HandleArguments;
|
||||
|
||||
/**
|
||||
* Handles the arguments, adding the cache directory and the cache result arguments.
|
||||
*/
|
||||
public function handleArguments(array $arguments): array
|
||||
{
|
||||
if (! $this->hasArgument('--log-junit', $arguments)) {
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
$logUnitArgument = null;
|
||||
|
||||
$arguments = array_filter($arguments, function (string $argument) use (&$logUnitArgument): bool {
|
||||
if (str_starts_with($argument, '--log-junit')) {
|
||||
$logUnitArgument = $argument;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
assert(is_string($logUnitArgument));
|
||||
|
||||
$arguments[] = $logUnitArgument;
|
||||
|
||||
return array_values($arguments);
|
||||
}
|
||||
}
|
||||
@ -13,7 +13,6 @@ use PHPUnit\Event\TestRunner\ConfiguredSubscriber;
|
||||
use PHPUnit\TextUI\Configuration\Configuration;
|
||||
use PHPUnit\TextUI\Output\DefaultPrinter;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@ -25,7 +24,6 @@ final class EnsureJunitEnabled implements ConfiguredSubscriber
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly InputInterface $input,
|
||||
private readonly OutputInterface $output,
|
||||
private readonly TestSuite $testSuite,
|
||||
) {
|
||||
}
|
||||
@ -39,9 +37,11 @@ final class EnsureJunitEnabled implements ConfiguredSubscriber
|
||||
return;
|
||||
}
|
||||
|
||||
$configuration = Container::getInstance()->get(Configuration::class);
|
||||
assert($configuration instanceof Configuration);
|
||||
|
||||
new JUnitLogger(
|
||||
DefaultPrinter::from(Container::getInstance()->get(Configuration::class)->logfileJunit()),
|
||||
$this->output,
|
||||
DefaultPrinter::from($configuration->logfileJunit()),
|
||||
new Converter($this->testSuite->rootPath),
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
|
||||
Pest Testing Framework 2.31.0.
|
||||
Pest Testing Framework 2.32.0.
|
||||
|
||||
USAGE: pest <file> [options]
|
||||
|
||||
@ -84,6 +84,7 @@
|
||||
--reverse-list .............................. Print defects in reverse order
|
||||
--teamcity . Replace default progress and result output with TeamCity format
|
||||
--testdox ................ Replace default result output with TestDox format
|
||||
--debug Replace default progress and result output with debugging information
|
||||
--compact ................ Replace default result output with Compact format
|
||||
|
||||
LOGGING OPTIONS:
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
|
||||
Pest Testing Framework 2.31.0.
|
||||
Pest Testing Framework 2.32.0.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user