Skip to content

Commit 74d2ac6

Browse files
Do not include information about the Git repository in the Open Test Reporting XML format by default
1 parent d775d50 commit 74d2ac6

30 files changed

+335
-79
lines changed

ChangeLog-12.2.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes of the PHPUnit 12.2 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
44

5+
## [12.2.4] - 2025-MM-DD
6+
7+
### Changed
8+
9+
* Including information about the Git repository (such as the commit hash and branch name) in the Open Test Reporting XML format is now an opt-in feature that can be enabled via the `--include-git-information` CLI option or the `includeGitInformation` attribute in the XML configuration file
10+
511
## [12.2.3] - 2025-06-20
612

713
### Added
@@ -76,6 +82,7 @@ This feature is experimental and the generated XML may change to enhance complia
7682
* A warning is now emitted when more than one of `#[Small]`, `#[Medium]`, or `#[Large]` is used on a test class
7783
* A warning is now emitted when a data provider provides data sets that have more values than the test method consumes using arguments
7884

85+
[12.2.4]: https://github.com/sebastianbergmann/phpunit/compare/12.2.3...12.2
7986
[12.2.3]: https://github.com/sebastianbergmann/phpunit/compare/12.2.2...12.2.3
8087
[12.2.2]: https://github.com/sebastianbergmann/phpunit/compare/12.2.1...12.2.2
8188
[12.2.1]: https://github.com/sebastianbergmann/phpunit/compare/12.2.0...12.2.1

phpunit.xsd

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@
299299
<xs:group name="loggingGroup">
300300
<xs:all>
301301
<xs:element name="junit" type="logToFileType" minOccurs="0" />
302-
<xs:element name="otr" type="logToFileType" minOccurs="0" />
302+
<xs:element name="otr" type="otrType" minOccurs="0" />
303303
<xs:element name="teamcity" type="logToFileType" minOccurs="0" />
304304
<xs:element name="testdoxHtml" type="logToFileType" minOccurs="0" />
305305
<xs:element name="testdoxText" type="logToFileType" minOccurs="0" />
@@ -311,6 +311,10 @@
311311
<xs:complexType name="logToDirectoryType">
312312
<xs:attribute name="outputDirectory" type="xs:anyURI" use="required"/>
313313
</xs:complexType>
314+
<xs:complexType name="otrType">
315+
<xs:attribute name="outputFile" type="xs:anyURI" use="required"/>
316+
<xs:attribute name="includeGitInformation" type="xs:boolean" default="false"/>
317+
</xs:complexType>
314318
<xs:complexType name="coverageReportCrap4JType">
315319
<xs:attribute name="outputFile" type="xs:anyURI" use="required"/>
316320
<xs:attribute name="threshold" type="xs:integer"/>

src/Logging/OpenTestReporting/OtrXmlLogger.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,14 @@ final class OtrXmlLogger
6969
private ?Throwable $parentErrored = null;
7070
private ?Throwable $parentFailed = null;
7171
private bool $alreadyFinished = false;
72+
private bool $includeGitInformation;
7273

7374
/**
7475
* @param non-empty-string $uri
7576
*
7677
* @throws CannotOpenUriForWritingException
7778
*/
78-
public function __construct(string $uri, Facade $facade)
79+
public function __construct(Facade $facade, string $uri, bool $includeGitInformation)
7980
{
8081
$this->writer = new XMLWriter;
8182

@@ -88,12 +89,18 @@ public function __construct(string $uri, Facade $facade)
8889
$this->writer->setIndent(true);
8990

9091
$this->registerSubscribers($facade);
92+
93+
$this->includeGitInformation = $includeGitInformation;
9194
}
9295

9396
public function testRunnerStarted(): void
9497
{
9598
$infrastructure = new InfrastructureInformationProvider;
96-
$gitInformation = $infrastructure->gitInformation();
99+
$gitInformation = false;
100+
101+
if ($this->includeGitInformation) {
102+
$gitInformation = $infrastructure->gitInformation();
103+
}
97104

98105
$this->writer->startDocument();
99106

src/TextUI/Application.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,9 @@ private function registerLogfileWriters(Configuration $configuration): void
655655
if ($configuration->hasLogfileOtr()) {
656656
try {
657657
new OtrXmlLogger(
658-
$configuration->logfileOtr(),
659658
EventFacade::instance(),
659+
$configuration->logfileOtr(),
660+
$configuration->includeGitInformationInOtrLogfile(),
660661
);
661662
} catch (CannotOpenUriForWritingException $e) {
662663
EventFacade::emitter()->testRunnerTriggeredPhpunitWarning(

src/TextUI/Configuration/Cli/Builder.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ final class Builder
9292
'list-tests-xml=',
9393
'log-junit=',
9494
'log-otr=',
95+
'include-git-information',
9596
'log-teamcity=',
9697
'migrate-configuration',
9798
'no-configuration',
@@ -275,6 +276,7 @@ public function fromParameters(array $parameters): Configuration
275276
$iniSettings = [];
276277
$junitLogfile = null;
277278
$otrLogfile = null;
279+
$includeGitInformation = null;
278280
$listGroups = false;
279281
$listSuites = false;
280282
$listTestFiles = false;
@@ -606,6 +608,11 @@ public function fromParameters(array $parameters): Configuration
606608

607609
break;
608610

611+
case '--include-git-information':
612+
$includeGitInformation = true;
613+
614+
break;
615+
609616
case '--log-teamcity':
610617
$teamcityLogfile = $option[1];
611618

@@ -1305,6 +1312,7 @@ public function fromParameters(array $parameters): Configuration
13051312
$iniSettings,
13061313
$junitLogfile,
13071314
$otrLogfile,
1315+
$includeGitInformation,
13081316
$listGroups,
13091317
$listSuites,
13101318
$listTestFiles,

src/TextUI/Configuration/Cli/Configuration.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
private ?array $iniSettings;
129129
private ?string $junitLogfile;
130130
private ?string $otrLogfile;
131+
private ?bool $includeGitInformationInOtrLogfile;
131132
private bool $listGroups;
132133
private bool $listSuites;
133134
private bool $listTestFiles;
@@ -192,7 +193,7 @@
192193
* @param ?non-empty-list<non-empty-string> $coverageFilter
193194
* @param ?non-empty-list<non-empty-string> $extensions
194195
*/
195-
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 $coverageOpenClover, ?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 $failOnAllIssues, ?bool $failOnDeprecation, ?bool $failOnPhpunitDeprecation, ?bool $failOnPhpunitNotice, ?bool $failOnPhpunitWarning, ?bool $failOnEmptyTestSuite, ?bool $failOnIncomplete, ?bool $failOnNotice, ?bool $failOnRisky, ?bool $failOnSkipped, ?bool $failOnWarning, ?bool $doNotFailOnDeprecation, ?bool $doNotFailOnPhpunitDeprecation, ?bool $doNotFailOnPhpunitNotice, ?bool $doNotFailOnPhpunitWarning, ?bool $doNotFailOnEmptyTestSuite, ?bool $doNotFailOnIncomplete, ?bool $doNotFailOnNotice, ?bool $doNotFailOnRisky, ?bool $doNotFailOnSkipped, ?bool $doNotFailOnWarning, ?bool $stopOnDefect, ?bool $stopOnDeprecation, ?string $specificDeprecationToStopOn, ?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, ?array $testsRequiringPhpExtension, bool $help, ?string $includePath, ?array $iniSettings, ?string $junitLogfile, ?string $otrLogfile, 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 $displayDetailsOnAllIssues, ?bool $displayDetailsOnIncompleteTests, ?bool $displayDetailsOnSkippedTests, ?bool $displayDetailsOnTestsThatTriggerDeprecations, ?bool $displayDetailsOnPhpunitDeprecations, ?bool $displayDetailsOnPhpunitNotices, ?bool $displayDetailsOnTestsThatTriggerErrors, ?bool $displayDetailsOnTestsThatTriggerNotices, ?bool $displayDetailsOnTestsThatTriggerWarnings, bool $version, ?array $coverageFilter, ?string $logEventsText, ?string $logEventsVerboseText, ?bool $printerTeamCity, ?bool $testdoxPrinter, ?bool $testdoxPrinterSummary, bool $debug, bool $withTelemetry, ?array $extensions)
196+
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 $coverageOpenClover, ?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 $failOnAllIssues, ?bool $failOnDeprecation, ?bool $failOnPhpunitDeprecation, ?bool $failOnPhpunitNotice, ?bool $failOnPhpunitWarning, ?bool $failOnEmptyTestSuite, ?bool $failOnIncomplete, ?bool $failOnNotice, ?bool $failOnRisky, ?bool $failOnSkipped, ?bool $failOnWarning, ?bool $doNotFailOnDeprecation, ?bool $doNotFailOnPhpunitDeprecation, ?bool $doNotFailOnPhpunitNotice, ?bool $doNotFailOnPhpunitWarning, ?bool $doNotFailOnEmptyTestSuite, ?bool $doNotFailOnIncomplete, ?bool $doNotFailOnNotice, ?bool $doNotFailOnRisky, ?bool $doNotFailOnSkipped, ?bool $doNotFailOnWarning, ?bool $stopOnDefect, ?bool $stopOnDeprecation, ?string $specificDeprecationToStopOn, ?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, ?array $testsRequiringPhpExtension, bool $help, ?string $includePath, ?array $iniSettings, ?string $junitLogfile, ?string $otrLogfile, ?bool $includeGitInformation, 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 $displayDetailsOnAllIssues, ?bool $displayDetailsOnIncompleteTests, ?bool $displayDetailsOnSkippedTests, ?bool $displayDetailsOnTestsThatTriggerDeprecations, ?bool $displayDetailsOnPhpunitDeprecations, ?bool $displayDetailsOnPhpunitNotices, ?bool $displayDetailsOnTestsThatTriggerErrors, ?bool $displayDetailsOnTestsThatTriggerNotices, ?bool $displayDetailsOnTestsThatTriggerWarnings, bool $version, ?array $coverageFilter, ?string $logEventsText, ?string $logEventsVerboseText, ?bool $printerTeamCity, ?bool $testdoxPrinter, ?bool $testdoxPrinterSummary, bool $debug, bool $withTelemetry, ?array $extensions)
196197
{
197198
$this->arguments = $arguments;
198199
$this->atLeastVersion = $atLeastVersion;
@@ -273,6 +274,7 @@ public function __construct(array $arguments, ?string $atLeastVersion, ?bool $ba
273274
$this->iniSettings = $iniSettings;
274275
$this->junitLogfile = $junitLogfile;
275276
$this->otrLogfile = $otrLogfile;
277+
$this->includeGitInformationInOtrLogfile = $includeGitInformation;
276278
$this->listGroups = $listGroups;
277279
$this->listSuites = $listSuites;
278280
$this->listTestFiles = $listTestFiles;
@@ -1810,6 +1812,26 @@ public function otrLogfile(): string
18101812
return $this->otrLogfile;
18111813
}
18121814

1815+
/**
1816+
* @phpstan-assert-if-true !null $this->includeGitInformationInOtrLogfile
1817+
*/
1818+
public function hasIncludeGitInformationInOtrLogfile(): bool
1819+
{
1820+
return $this->includeGitInformationInOtrLogfile !== null;
1821+
}
1822+
1823+
/**
1824+
* @throws Exception
1825+
*/
1826+
public function includeGitInformationInOtrLogfile(): bool
1827+
{
1828+
if (!$this->hasIncludeGitInformationInOtrLogfile()) {
1829+
throw new Exception;
1830+
}
1831+
1832+
return $this->includeGitInformationInOtrLogfile;
1833+
}
1834+
18131835
public function listGroups(): bool
18141836
{
18151837
return $this->listGroups;

0 commit comments

Comments
 (0)