Skip to content

Commit

Permalink
Closes #5937
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Sep 4, 2024
1 parent 43e7c3e commit 1a5d2b8
Show file tree
Hide file tree
Showing 24 changed files with 191 additions and 13 deletions.
7 changes: 7 additions & 0 deletions ChangeLog-10.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

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

## [10.5.32] - 2024-MM-DD

### Added

* [#5937](https://github.com/sebastianbergmann/phpunit/issues/5937): Optionally ignore PHPUnit deprecations when determining the test runner's shell exit code

This comment has been minimized.

Copy link
@jrfnl

jrfnl Sep 4, 2024

Contributor

Based on the implementation of this change, I think the wording of this entry may need clarification.

-* [#5937](https://github.com/sebastianbergmann/phpunit/issues/5937): Optionally ignore PHPUnit deprecations when determining the test runner's shell exit code
+* [#5937](https://github.com/sebastianbergmann/phpunit/issues/5937): PHPUnit deprecations will, by default, no longer affect the test runner's shell exit code. This can optionally be turned back on using the `--fail-on-phpunit-deprecation` CLI option or the `failOnPhpunitDeprecation="true"` XML configuration option.

## [10.5.31] - 2024-09-03

### Changed
Expand Down Expand Up @@ -282,6 +288,7 @@ All notable changes of the PHPUnit 10.5 release series are documented in this fi

* [#5563](https://github.com/sebastianbergmann/phpunit/issues/5563): `createMockForIntersectionOfInterfaces()` does not automatically register mock object for expectation verification

[10.5.32]: https://github.com/sebastianbergmann/phpunit/compare/10.5.31...10.5
[10.5.31]: https://github.com/sebastianbergmann/phpunit/compare/10.5.30...10.5.31
[10.5.30]: https://github.com/sebastianbergmann/phpunit/compare/10.5.29...10.5.30
[10.5.29]: https://github.com/sebastianbergmann/phpunit/compare/10.5.28...10.5.29
Expand Down
1 change: 1 addition & 0 deletions phpunit.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
<xs:attribute name="requireCoverageMetadata" type="xs:boolean" default="false"/>
<xs:attribute name="processIsolation" type="xs:boolean" default="false"/>
<xs:attribute name="failOnDeprecation" type="xs:boolean" default="false"/>
<xs:attribute name="failOnPhpunitDeprecation" type="xs:boolean" default="false"/>
<xs:attribute name="failOnEmptyTestSuite" type="xs:boolean" default="false"/>
<xs:attribute name="failOnIncomplete" type="xs:boolean" default="false"/>
<xs:attribute name="failOnNotice" type="xs:boolean" default="false"/>
Expand Down
10 changes: 10 additions & 0 deletions src/Runner/TestResult/TestResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,16 @@ public function hasDeprecations(): bool
return $this->numberOfDeprecations() > 0;
}

public function hasPhpOrUserDeprecations(): bool
{
return count($this->phpDeprecations) > 0 || count($this->deprecations) > 0;
}

public function hasPhpunitDeprecations(): bool
{
return count($this->testTriggeredPhpunitDeprecationEvents) > 0 || count($this->testRunnerTriggeredDeprecationEvents) > 0;
}

public function numberOfDeprecations(): int
{
return count($this->deprecations) +
Expand Down
1 change: 1 addition & 0 deletions src/TextUI/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ public function run(array $argv): int

$shellExitCode = (new ShellExitCodeCalculator)->calculate(
$configuration->failOnDeprecation(),
$configuration->failOnPhpunitDeprecation(),
$configuration->failOnEmptyTestSuite(),
$configuration->failOnIncomplete(),
$configuration->failOnNotice(),
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 @@ -101,6 +101,7 @@ final class Builder
'static-backup',
'stderr',
'fail-on-deprecation',
'fail-on-phpunit-deprecation',
'fail-on-empty-test-suite',
'fail-on-incomplete',
'fail-on-notice',
Expand Down Expand Up @@ -196,6 +197,7 @@ public function fromParameters(array $parameters): Configuration
$executionOrder = null;
$executionOrderDefects = null;
$failOnDeprecation = null;
$failOnPhpunitDeprecation = null;
$failOnEmptyTestSuite = null;
$failOnIncomplete = null;
$failOnNotice = null;
Expand Down Expand Up @@ -569,6 +571,11 @@ public function fromParameters(array $parameters): Configuration

break;

case '--fail-on-phpunit-deprecation':
$failOnPhpunitDeprecation = true;

break;

case '--fail-on-empty-test-suite':
$failOnEmptyTestSuite = true;

Expand Down Expand Up @@ -911,6 +918,7 @@ public function fromParameters(array $parameters): Configuration
$executionOrder,
$executionOrderDefects,
$failOnDeprecation,
$failOnPhpunitDeprecation,
$failOnEmptyTestSuite,
$failOnIncomplete,
$failOnNotice,
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 @@ -55,6 +55,7 @@ final class Configuration
private readonly ?int $executionOrder;
private readonly ?int $executionOrderDefects;
private readonly ?bool $failOnDeprecation;
private readonly ?bool $failOnPhpunitDeprecation;
private readonly ?bool $failOnEmptyTestSuite;
private readonly ?bool $failOnIncomplete;
private readonly ?bool $failOnNotice;
Expand Down Expand Up @@ -128,7 +129,7 @@ final class Configuration
* @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, ?string $cacheResultFile, 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, ?string $coverageCacheDirectory, 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 $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 $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, ?string $cacheResultFile, 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, ?string $coverageCacheDirectory, bool $warmCoverageCache, ?int $defaultTimeLimit, ?bool $disableCodeCoverageIgnore, ?bool $disallowTestOutput, ?bool $enforceTimeLimit, ?array $excludeGroups, ?int $executionOrder, ?int $executionOrderDefects, ?bool $failOnDeprecation, ?bool $failOnPhpunitDeprecation, ?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 $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 $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 @@ -164,6 +165,7 @@ public function __construct(array $arguments, ?string $atLeastVersion, ?bool $ba
$this->executionOrder = $executionOrder;
$this->executionOrderDefects = $executionOrderDefects;
$this->failOnDeprecation = $failOnDeprecation;
$this->failOnPhpunitDeprecation = $failOnPhpunitDeprecation;
$this->failOnEmptyTestSuite = $failOnEmptyTestSuite;
$this->failOnIncomplete = $failOnIncomplete;
$this->failOnNotice = $failOnNotice;
Expand Down Expand Up @@ -876,6 +878,26 @@ public function failOnDeprecation(): bool
return $this->failOnDeprecation;
}

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

/**
* @throws Exception
*/
public function failOnPhpunitDeprecation(): bool
{
if (!$this->hasFailOnPhpunitDeprecation()) {
throw new Exception;
}

return $this->failOnPhpunitDeprecation;
}

/**
* @psalm-assert-if-true !null $this->failOnEmptyTestSuite
*/
Expand Down
9 changes: 8 additions & 1 deletion src/TextUI/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ final class Configuration
private readonly bool $ignoreDeprecatedCodeUnitsFromCodeCoverage;
private readonly bool $disableCodeCoverageIgnore;
private readonly bool $failOnDeprecation;
private readonly bool $failOnPhpunitDeprecation;
private readonly bool $failOnEmptyTestSuite;
private readonly bool $failOnIncomplete;
private readonly bool $failOnNotice;
Expand Down Expand Up @@ -146,7 +147,7 @@ final class Configuration
* @psalm-param non-empty-list<non-empty-string> $testSuffixes
* @psalm-param list<array{className: class-string, parameters: array<string, string>}> $extensionBootstrappers
*/
public function __construct(array $cliArguments, ?string $configurationFile, ?string $bootstrap, bool $cacheResult, ?string $cacheDirectory, ?string $coverageCacheDirectory, Source $source, string $testResultCacheFile, ?string $coverageClover, ?string $coverageCobertura, ?string $coverageCrap4j, int $coverageCrap4jThreshold, ?string $coverageHtml, int $coverageHtmlLowUpperBound, int $coverageHtmlHighLowerBound, string $coverageHtmlColorSuccessLow, string $coverageHtmlColorSuccessMedium, string $coverageHtmlColorSuccessHigh, string $coverageHtmlColorWarning, string $coverageHtmlColorDanger, ?string $coverageHtmlCustomCssFile, ?string $coveragePhp, ?string $coverageText, bool $coverageTextShowUncoveredFiles, bool $coverageTextShowOnlySummary, ?string $coverageXml, bool $pathCoverage, bool $ignoreDeprecatedCodeUnitsFromCodeCoverage, bool $disableCodeCoverageIgnore, 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, bool $outputToStandardErrorStream, int|string $columns, bool $noExtensions, ?string $pharExtensionDirectory, array $extensionBootstrappers, bool $backupGlobals, bool $backupStaticProperties, bool $beStrictAboutChangesToGlobalState, bool $colors, bool $processIsolation, bool $enforceTimeLimit, int $defaultTimeLimit, int $timeoutForSmallTests, int $timeoutForMediumTests, int $timeoutForLargeTests, bool $reportUselessTests, bool $strictCoverage, bool $disallowTestOutput, bool $displayDetailsOnIncompleteTests, bool $displayDetailsOnSkippedTests, bool $displayDetailsOnTestsThatTriggerDeprecations, bool $displayDetailsOnTestsThatTriggerErrors, bool $displayDetailsOnTestsThatTriggerNotices, bool $displayDetailsOnTestsThatTriggerWarnings, bool $reverseDefectList, bool $requireCoverageMetadata, bool $registerMockObjectsFromTestArgumentsRecursively, bool $noProgress, bool $noResults, bool $noOutput, int $executionOrder, int $executionOrderDefects, bool $resolveDependencies, ?string $logfileTeamcity, ?string $logfileJunit, ?string $logfileTestdoxHtml, ?string $logfileTestdoxText, ?string $logEventsText, ?string $logEventsVerboseText, bool $teamCityOutput, bool $testDoxOutput, ?array $testsCovering, ?array $testsUsing, ?string $filter, ?array $groups, ?array $excludeGroups, int $randomOrderSeed, bool $includeUncoveredFiles, TestSuiteCollection $testSuite, string $includeTestSuite, string $excludeTestSuite, ?string $defaultTestSuite, array $testSuffixes, Php $php, bool $controlGarbageCollector, int $numberOfTestsBeforeGarbageCollection, ?string $generateBaseline, bool $debug)
public function __construct(array $cliArguments, ?string $configurationFile, ?string $bootstrap, bool $cacheResult, ?string $cacheDirectory, ?string $coverageCacheDirectory, Source $source, string $testResultCacheFile, ?string $coverageClover, ?string $coverageCobertura, ?string $coverageCrap4j, int $coverageCrap4jThreshold, ?string $coverageHtml, int $coverageHtmlLowUpperBound, int $coverageHtmlHighLowerBound, string $coverageHtmlColorSuccessLow, string $coverageHtmlColorSuccessMedium, string $coverageHtmlColorSuccessHigh, string $coverageHtmlColorWarning, string $coverageHtmlColorDanger, ?string $coverageHtmlCustomCssFile, ?string $coveragePhp, ?string $coverageText, bool $coverageTextShowUncoveredFiles, bool $coverageTextShowOnlySummary, ?string $coverageXml, bool $pathCoverage, bool $ignoreDeprecatedCodeUnitsFromCodeCoverage, bool $disableCodeCoverageIgnore, bool $failOnDeprecation, bool $failOnPhpunitDeprecation, 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, bool $outputToStandardErrorStream, int|string $columns, bool $noExtensions, ?string $pharExtensionDirectory, array $extensionBootstrappers, bool $backupGlobals, bool $backupStaticProperties, bool $beStrictAboutChangesToGlobalState, bool $colors, bool $processIsolation, bool $enforceTimeLimit, int $defaultTimeLimit, int $timeoutForSmallTests, int $timeoutForMediumTests, int $timeoutForLargeTests, bool $reportUselessTests, bool $strictCoverage, bool $disallowTestOutput, bool $displayDetailsOnIncompleteTests, bool $displayDetailsOnSkippedTests, bool $displayDetailsOnTestsThatTriggerDeprecations, bool $displayDetailsOnTestsThatTriggerErrors, bool $displayDetailsOnTestsThatTriggerNotices, bool $displayDetailsOnTestsThatTriggerWarnings, bool $reverseDefectList, bool $requireCoverageMetadata, bool $registerMockObjectsFromTestArgumentsRecursively, bool $noProgress, bool $noResults, bool $noOutput, int $executionOrder, int $executionOrderDefects, bool $resolveDependencies, ?string $logfileTeamcity, ?string $logfileJunit, ?string $logfileTestdoxHtml, ?string $logfileTestdoxText, ?string $logEventsText, ?string $logEventsVerboseText, bool $teamCityOutput, bool $testDoxOutput, ?array $testsCovering, ?array $testsUsing, ?string $filter, ?array $groups, ?array $excludeGroups, int $randomOrderSeed, bool $includeUncoveredFiles, TestSuiteCollection $testSuite, string $includeTestSuite, string $excludeTestSuite, ?string $defaultTestSuite, array $testSuffixes, Php $php, bool $controlGarbageCollector, int $numberOfTestsBeforeGarbageCollection, ?string $generateBaseline, bool $debug)
{
$this->cliArguments = $cliArguments;
$this->configurationFile = $configurationFile;
Expand Down Expand Up @@ -178,6 +179,7 @@ public function __construct(array $cliArguments, ?string $configurationFile, ?st
$this->ignoreDeprecatedCodeUnitsFromCodeCoverage = $ignoreDeprecatedCodeUnitsFromCodeCoverage;
$this->disableCodeCoverageIgnore = $disableCodeCoverageIgnore;
$this->failOnDeprecation = $failOnDeprecation;
$this->failOnPhpunitDeprecation = $failOnPhpunitDeprecation;
$this->failOnEmptyTestSuite = $failOnEmptyTestSuite;
$this->failOnIncomplete = $failOnIncomplete;
$this->failOnNotice = $failOnNotice;
Expand Down Expand Up @@ -695,6 +697,11 @@ public function failOnDeprecation(): bool
return $this->failOnDeprecation;
}

public function failOnPhpunitDeprecation(): bool
{
return $this->failOnPhpunitDeprecation;
}

public function failOnEmptyTestSuite(): bool
{
return $this->failOnEmptyTestSuite;
Expand Down
7 changes: 7 additions & 0 deletions src/TextUI/Configuration/Merger.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ public function merge(CliConfiguration $cliConfiguration, XmlConfiguration $xmlC
$failOnDeprecation = $xmlConfiguration->phpunit()->failOnDeprecation();
}

if ($cliConfiguration->hasFailOnPhpunitDeprecation()) {
$failOnPhpunitDeprecation = $cliConfiguration->failOnPhpunitDeprecation();
} else {
$failOnPhpunitDeprecation = $xmlConfiguration->phpunit()->failOnPhpunitDeprecation();
}

if ($cliConfiguration->hasFailOnEmptyTestSuite()) {
$failOnEmptyTestSuite = $cliConfiguration->failOnEmptyTestSuite();
} else {
Expand Down Expand Up @@ -775,6 +781,7 @@ public function merge(CliConfiguration $cliConfiguration, XmlConfiguration $xmlC
$xmlConfiguration->codeCoverage()->ignoreDeprecatedCodeUnits(),
$disableCodeCoverageIgnore,
$failOnDeprecation,
$failOnPhpunitDeprecation,
$failOnEmptyTestSuite,
$failOnIncomplete,
$failOnNotice,
Expand Down
1 change: 1 addition & 0 deletions src/TextUI/Configuration/Xml/DefaultConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public static function create(): self
false,
false,
false,
false,
null,
false,
false,
Expand Down
1 change: 1 addition & 0 deletions src/TextUI/Configuration/Xml/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ final class Generator
requireCoverageMetadata="true"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
failOnPhpunitDeprecation="true"
failOnRisky="true"
failOnWarning="true">
<testsuites>
Expand Down
Loading

0 comments on commit 1a5d2b8

Please sign in to comment.