Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New XML-based logfile format #5388

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .psalm/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,8 @@
)]]></code>
<code><![CDATA[OutputFacade::printerFor($configuration->logfileJunit())]]></code>
<code><![CDATA[OutputFacade::printerFor($configuration->logfileJunit())]]></code>
<code><![CDATA[OutputFacade::printerFor($configuration->logfileXml())]]></code>
<code><![CDATA[OutputFacade::printerFor($configuration->logfileXml())]]></code>
<code><![CDATA[atLeastVersion]]></code>
<code><![CDATA[build]]></code>
<code><![CDATA[configurationFile]]></code>
Expand All @@ -714,6 +716,7 @@
<code><![CDATA[logEventsVerboseText]]></code>
<code><![CDATA[logfileJunit]]></code>
<code><![CDATA[logfileTeamcity]]></code>
<code><![CDATA[logfileXml]]></code>
</MissingThrowsDocblock>
<UnresolvableInclude>
<code><![CDATA[include_once $filename]]></code>
Expand Down
1 change: 1 addition & 0 deletions phpunit.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@
</xs:group>
<xs:group name="loggingGroup">
<xs:all>
<xs:element name="xml" type="logToFileType" minOccurs="0" />
<xs:element name="junit" type="logToFileType" minOccurs="0" />
<xs:element name="teamcity" type="logToFileType" minOccurs="0" />
<xs:element name="testdoxHtml" type="logToFileType" minOccurs="0" />
Expand Down
28 changes: 28 additions & 0 deletions src/Logging/Xml/Subscriber/Subscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Logging\Xml;

/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
abstract class Subscriber
{
private readonly XmlLogger $logger;

public function __construct(XmlLogger $logger)
{
$this->logger = $logger;
}

protected function logger(): XmlLogger
{
return $this->logger;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Logging\Xml;

use PHPUnit\Event\TestRunner\ExecutionFinished;
use PHPUnit\Event\TestRunner\ExecutionFinishedSubscriber;

/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class TestRunnerExecutionFinishedSubscriber extends Subscriber implements ExecutionFinishedSubscriber
{
public function notify(ExecutionFinished $event): void
{
$this->logger()->flush();
}
}
52 changes: 52 additions & 0 deletions src/Logging/Xml/XmlLogger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Logging\Xml;

use PHPUnit\Event\EventFacadeIsSealedException;
use PHPUnit\Event\Facade;
use PHPUnit\Event\UnknownSubscriberTypeException;
use PHPUnit\TextUI\Output\Printer;

/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class XmlLogger
{
private readonly Printer $printer;

/**
* @throws EventFacadeIsSealedException
* @throws UnknownSubscriberTypeException
*/
public function __construct(Printer $printer, Facade $facade)
{
$this->printer = $printer;

$this->registerSubscribers($facade);
}

public function flush(): void
{
$this->printer->print('todo');

$this->printer->flush();
}

/**
* @throws EventFacadeIsSealedException
* @throws UnknownSubscriberTypeException
*/
private function registerSubscribers(Facade $facade): void
{
$facade->registerSubscribers(
new TestRunnerExecutionFinishedSubscriber($this),
);
}
}
8 changes: 8 additions & 0 deletions src/TextUI/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use PHPUnit\Logging\TestDox\HtmlRenderer as TestDoxHtmlRenderer;
use PHPUnit\Logging\TestDox\PlainTextRenderer as TestDoxTextRenderer;
use PHPUnit\Logging\TestDox\TestResultCollector as TestDoxResultCollector;
use PHPUnit\Logging\Xml\XmlLogger;
use PHPUnit\Runner\Baseline\CannotLoadBaselineException;
use PHPUnit\Runner\Baseline\Generator as BaselineGenerator;
use PHPUnit\Runner\Baseline\Reader;
Expand Down Expand Up @@ -531,6 +532,13 @@ private function registerLogfileWriters(Configuration $configuration): void
);
}

if ($configuration->hasLogfileXml()) {
new XmlLogger(
OutputFacade::printerFor($configuration->logfileXml()),
EventFacade::instance(),
);
}

if ($configuration->hasLogfileJunit()) {
new JunitXmlLogger(
OutputFacade::printerFor($configuration->logfileJunit()),
Expand Down
8 changes: 8 additions & 0 deletions src/TextUI/Configuration/Cli/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ final class Builder
'list-tests-xml=',
'log-junit=',
'log-teamcity=',
'log-xml=',
'migrate-configuration',
'no-configuration',
'no-coverage',
Expand Down Expand Up @@ -220,6 +221,7 @@ public function fromParameters(array $parameters): Configuration
$includePath = null;
$iniSettings = [];
$junitLogfile = null;
$xmlLogfile = null;
$listGroups = false;
$listSuites = false;
$listTestFiles = false;
Expand Down Expand Up @@ -544,6 +546,11 @@ public function fromParameters(array $parameters): Configuration

break;

case '--log-xml':
$xmlLogfile = $option[1];

break;

case '--order-by':
foreach (explode(',', $option[1]) as $order) {
switch ($order) {
Expand Down Expand Up @@ -982,6 +989,7 @@ public function fromParameters(array $parameters): Configuration
$help,
$includePath,
$iniSettings,
$xmlLogfile,
$junitLogfile,
$listGroups,
$listSuites,
Expand Down
24 changes: 23 additions & 1 deletion src/TextUI/Configuration/Cli/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
private bool $help;
private ?string $includePath;
private ?array $iniSettings;
private ?string $xmlLogfile;
private ?string $junitLogfile;
private bool $listGroups;
private bool $listSuites;
Expand Down Expand Up @@ -126,7 +127,7 @@
* @psalm-param list<non-empty-string> $arguments
* @psalm-param ?non-empty-list<non-empty-string> $testSuffixes
*/
public function __construct(array $arguments, ?string $atLeastVersion, ?bool $backupGlobals, ?bool $backupStaticProperties, ?bool $beStrictAboutChangesToGlobalState, ?string $bootstrap, ?string $cacheDirectory, ?bool $cacheResult, bool $checkVersion, ?string $colors, null|int|string $columns, ?string $configurationFile, ?string $coverageClover, ?string $coverageCobertura, ?string $coverageCrap4J, ?string $coverageHtml, ?string $coveragePhp, ?string $coverageText, ?bool $coverageTextShowUncoveredFiles, ?bool $coverageTextShowOnlySummary, ?string $coverageXml, ?bool $pathCoverage, bool $warmCoverageCache, ?int $defaultTimeLimit, ?bool $disableCodeCoverageIgnore, ?bool $disallowTestOutput, ?bool $enforceTimeLimit, ?array $excludeGroups, ?int $executionOrder, ?int $executionOrderDefects, ?bool $failOnDeprecation, ?bool $failOnEmptyTestSuite, ?bool $failOnIncomplete, ?bool $failOnNotice, ?bool $failOnRisky, ?bool $failOnSkipped, ?bool $failOnWarning, ?bool $stopOnDefect, ?bool $stopOnDeprecation, ?bool $stopOnError, ?bool $stopOnFailure, ?bool $stopOnIncomplete, ?bool $stopOnNotice, ?bool $stopOnRisky, ?bool $stopOnSkipped, ?bool $stopOnWarning, ?string $filter, ?string $excludeFilter, ?string $generateBaseline, ?string $useBaseline, bool $ignoreBaseline, bool $generateConfiguration, bool $migrateConfiguration, ?array $groups, ?array $testsCovering, ?array $testsUsing, bool $help, ?string $includePath, ?array $iniSettings, ?string $junitLogfile, bool $listGroups, bool $listSuites, bool $listTestFiles, bool $listTests, ?string $listTestsXml, ?bool $noCoverage, ?bool $noExtensions, ?bool $noOutput, ?bool $noProgress, ?bool $noResults, ?bool $noLogging, ?bool $processIsolation, ?int $randomOrderSeed, ?bool $reportUselessTests, ?bool $resolveDependencies, ?bool $reverseList, ?bool $stderr, ?bool $strictCoverage, ?string $teamcityLogfile, ?string $testdoxHtmlFile, ?string $testdoxTextFile, ?array $testSuffixes, ?string $testSuite, ?string $excludeTestSuite, bool $useDefaultConfiguration, ?bool $displayDetailsOnIncompleteTests, ?bool $displayDetailsOnSkippedTests, ?bool $displayDetailsOnTestsThatTriggerDeprecations, ?bool $displayDetailsOnTestsThatTriggerErrors, ?bool $displayDetailsOnTestsThatTriggerNotices, ?bool $displayDetailsOnTestsThatTriggerWarnings, bool $version, ?array $coverageFilter, ?string $logEventsText, ?string $logEventsVerboseText, ?bool $printerTeamCity, ?bool $printerTestDox, bool $debug)
public function __construct(array $arguments, ?string $atLeastVersion, ?bool $backupGlobals, ?bool $backupStaticProperties, ?bool $beStrictAboutChangesToGlobalState, ?string $bootstrap, ?string $cacheDirectory, ?bool $cacheResult, bool $checkVersion, ?string $colors, null|int|string $columns, ?string $configurationFile, ?string $coverageClover, ?string $coverageCobertura, ?string $coverageCrap4J, ?string $coverageHtml, ?string $coveragePhp, ?string $coverageText, ?bool $coverageTextShowUncoveredFiles, ?bool $coverageTextShowOnlySummary, ?string $coverageXml, ?bool $pathCoverage, bool $warmCoverageCache, ?int $defaultTimeLimit, ?bool $disableCodeCoverageIgnore, ?bool $disallowTestOutput, ?bool $enforceTimeLimit, ?array $excludeGroups, ?int $executionOrder, ?int $executionOrderDefects, ?bool $failOnDeprecation, ?bool $failOnEmptyTestSuite, ?bool $failOnIncomplete, ?bool $failOnNotice, ?bool $failOnRisky, ?bool $failOnSkipped, ?bool $failOnWarning, ?bool $stopOnDefect, ?bool $stopOnDeprecation, ?bool $stopOnError, ?bool $stopOnFailure, ?bool $stopOnIncomplete, ?bool $stopOnNotice, ?bool $stopOnRisky, ?bool $stopOnSkipped, ?bool $stopOnWarning, ?string $filter, ?string $excludeFilter, ?string $generateBaseline, ?string $useBaseline, bool $ignoreBaseline, bool $generateConfiguration, bool $migrateConfiguration, ?array $groups, ?array $testsCovering, ?array $testsUsing, bool $help, ?string $includePath, ?array $iniSettings, ?string $xmlLogfile, ?string $junitLogfile, bool $listGroups, bool $listSuites, bool $listTestFiles, bool $listTests, ?string $listTestsXml, ?bool $noCoverage, ?bool $noExtensions, ?bool $noOutput, ?bool $noProgress, ?bool $noResults, ?bool $noLogging, ?bool $processIsolation, ?int $randomOrderSeed, ?bool $reportUselessTests, ?bool $resolveDependencies, ?bool $reverseList, ?bool $stderr, ?bool $strictCoverage, ?string $teamcityLogfile, ?string $testdoxHtmlFile, ?string $testdoxTextFile, ?array $testSuffixes, ?string $testSuite, ?string $excludeTestSuite, bool $useDefaultConfiguration, ?bool $displayDetailsOnIncompleteTests, ?bool $displayDetailsOnSkippedTests, ?bool $displayDetailsOnTestsThatTriggerDeprecations, ?bool $displayDetailsOnTestsThatTriggerErrors, ?bool $displayDetailsOnTestsThatTriggerNotices, ?bool $displayDetailsOnTestsThatTriggerWarnings, bool $version, ?array $coverageFilter, ?string $logEventsText, ?string $logEventsVerboseText, ?bool $printerTeamCity, ?bool $printerTestDox, bool $debug)
{
$this->arguments = $arguments;
$this->atLeastVersion = $atLeastVersion;
Expand Down Expand Up @@ -188,6 +189,7 @@
$this->help = $help;
$this->includePath = $includePath;
$this->iniSettings = $iniSettings;
$this->xmlLogfile = $xmlLogfile;
$this->junitLogfile = $junitLogfile;
$this->listGroups = $listGroups;
$this->listSuites = $listSuites;
Expand Down Expand Up @@ -1326,6 +1328,26 @@
return $this->iniSettings;
}

/**
* @psalm-assert-if-true !null $this->xmlLogfile
*/
public function hasXmlLogfile(): bool
{
return $this->xmlLogfile !== null;
}

/**
* @throws Exception
*/
public function xmlLogfile(): string
{
if (!$this->hasXmlLogfile()) {
throw new Exception;

Check warning on line 1345 in src/TextUI/Configuration/Cli/Configuration.php

View check run for this annotation

Codecov / codecov/patch

src/TextUI/Configuration/Cli/Configuration.php#L1345

Added line #L1345 was not covered by tests
}

return $this->xmlLogfile;
}

/**
* @psalm-assert-if-true !null $this->junitLogfile
*/
Expand Down