junit support

This commit is contained in:
Adrian Nürnberger
2023-07-30 08:35:00 +02:00
parent 8f738f5d49
commit e5dc6f0ae2
14 changed files with 874 additions and 0 deletions

View File

@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
namespace Pest\Subscribers;
use Pest\Logging\JUnit\JUnitLogger;
use Pest\Logging\JUnit\Converter;
use Pest\Support\Container;
use Pest\TestSuite;
use PHPUnit\Event\TestRunner\Configured;
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
*/
final class EnsureJunitEnabled implements ConfiguredSubscriber
{
/**
* Creates a new Configured Subscriber instance.
*/
public function __construct(
private readonly InputInterface $input,
private readonly OutputInterface $output,
private readonly TestSuite $testSuite,
) {
}
/**
* Runs the subscriber.
*/
public function notify(Configured $event): void
{
if (! $this->input->hasParameterOption('--log-junit')) {
return;
}
new JUnitLogger(
DefaultPrinter::from(Container::getInstance()->get(Configuration::class)->logfileJunit()),
$this->output,
new Converter($this->testSuite->rootPath),
);
}
}