Skip to content

Commit 16d1b86

Browse files
Closes #5954
1 parent 71215c7 commit 16d1b86

File tree

10 files changed

+195
-4
lines changed

10 files changed

+195
-4
lines changed

ChangeLog-11.5.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All notable changes of the PHPUnit 11.5 release series are documented in this fi
77
### Added
88

99
* [#5948](https://github.com/sebastianbergmann/phpunit/pull/5948): Support for Property Hooks in Test Doubles
10+
* [#5954](https://github.com/sebastianbergmann/phpunit/issues/5954): Provide a way to stop execution at a particular deprecation
1011
* [#5998](https://github.com/sebastianbergmann/phpunit/pull/5998): Do not run `SKIPIF` section of PHPT test in separate process when it is free of side effects
1112
* [#5999](https://github.com/sebastianbergmann/phpunit/pull/5999): Do not run `CLEAN` section of PHPT test in separate process when it is free of side effects that modify the parent process
1213
* `TestRunner\ChildProcessStarted` and `TestRunner\ChildProcessFinished` events

src/Runner/TestResult/Facade.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
*/
1010
namespace PHPUnit\TestRunner\TestResult;
1111

12+
use function str_contains;
1213
use PHPUnit\Event\EventFacadeIsSealedException;
1314
use PHPUnit\Event\Facade as EventFacade;
1415
use PHPUnit\Event\UnknownSubscriberTypeException;
16+
use PHPUnit\Runner\DeprecationCollector\Facade as DeprecationCollectorFacade;
1517
use PHPUnit\TestRunner\IssueFilter;
18+
use PHPUnit\TextUI\Configuration\Configuration;
1619
use PHPUnit\TextUI\Configuration\Registry as ConfigurationRegistry;
1720

1821
/**
@@ -67,7 +70,7 @@ public static function shouldStop(): bool
6770
return true;
6871
}
6972

70-
if ($configuration->stopOnDeprecation() && $collector->hasDeprecations()) {
73+
if (self::stopOnDeprecation($configuration)) {
7174
return true;
7275
}
7376

@@ -103,4 +106,25 @@ private static function collector(): Collector
103106

104107
return self::$collector;
105108
}
109+
110+
private static function stopOnDeprecation(Configuration $configuration): bool
111+
{
112+
if (!$configuration->stopOnDeprecation()) {
113+
return false;
114+
}
115+
116+
$deprecations = DeprecationCollectorFacade::deprecations();
117+
118+
if (!$configuration->hasSpecificDeprecationToStopOn()) {
119+
return $deprecations !== [];
120+
}
121+
122+
foreach ($deprecations as $deprecation) {
123+
if (str_contains($deprecation, $configuration->specificDeprecationToStopOn())) {
124+
return true;
125+
}
126+
}
127+
128+
return false;
129+
}
106130
}

src/TextUI/Configuration/Cli/Builder.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ final class Builder
115115
'fail-on-skipped',
116116
'fail-on-warning',
117117
'stop-on-defect',
118-
'stop-on-deprecation',
118+
'stop-on-deprecation==',
119119
'stop-on-error',
120120
'stop-on-failure',
121121
'stop-on-incomplete',
@@ -215,6 +215,7 @@ public function fromParameters(array $parameters): Configuration
215215
$failOnWarning = null;
216216
$stopOnDefect = null;
217217
$stopOnDeprecation = null;
218+
$specificDeprecationToStopOn = null;
218219
$stopOnError = null;
219220
$stopOnFailure = null;
220221
$stopOnIncomplete = null;
@@ -703,6 +704,10 @@ public function fromParameters(array $parameters): Configuration
703704
case '--stop-on-deprecation':
704705
$stopOnDeprecation = true;
705706

707+
if ($option[1] !== null) {
708+
$specificDeprecationToStopOn = $option[1];
709+
}
710+
706711
break;
707712

708713
case '--stop-on-error':
@@ -1035,6 +1040,7 @@ public function fromParameters(array $parameters): Configuration
10351040
$failOnWarning,
10361041
$stopOnDefect,
10371042
$stopOnDeprecation,
1043+
$specificDeprecationToStopOn,
10381044
$stopOnError,
10391045
$stopOnFailure,
10401046
$stopOnIncomplete,

src/TextUI/Configuration/Cli/Configuration.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
private ?bool $failOnWarning;
7171
private ?bool $stopOnDefect;
7272
private ?bool $stopOnDeprecation;
73+
private ?string $specificDeprecationToStopOn;
7374
private ?bool $stopOnError;
7475
private ?bool $stopOnFailure;
7576
private ?bool $stopOnIncomplete;
@@ -173,7 +174,7 @@
173174
* @param ?non-empty-list<non-empty-string> $coverageFilter
174175
* @param ?non-empty-list<non-empty-string> $extensions
175176
*/
176-
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 $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 $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, 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 $displayDetailsOnPhpunitDeprecations, ?bool $displayDetailsOnTestsThatTriggerErrors, ?bool $displayDetailsOnTestsThatTriggerNotices, ?bool $displayDetailsOnTestsThatTriggerWarnings, bool $version, ?array $coverageFilter, ?string $logEventsText, ?string $logEventsVerboseText, ?bool $printerTeamCity, ?bool $testdoxPrinter, ?bool $testdoxPrinterSummary, bool $debug, ?array $extensions)
177+
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 $failOnPhpunitDeprecation, ?bool $failOnEmptyTestSuite, ?bool $failOnIncomplete, ?bool $failOnNotice, ?bool $failOnRisky, ?bool $failOnSkipped, ?bool $failOnWarning, ?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, 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 $displayDetailsOnPhpunitDeprecations, ?bool $displayDetailsOnTestsThatTriggerErrors, ?bool $displayDetailsOnTestsThatTriggerNotices, ?bool $displayDetailsOnTestsThatTriggerWarnings, bool $version, ?array $coverageFilter, ?string $logEventsText, ?string $logEventsVerboseText, ?bool $printerTeamCity, ?bool $testdoxPrinter, ?bool $testdoxPrinterSummary, bool $debug, ?array $extensions)
177178
{
178179
$this->arguments = $arguments;
179180
$this->atLeastVersion = $atLeastVersion;
@@ -216,6 +217,7 @@ public function __construct(array $arguments, ?string $atLeastVersion, ?bool $ba
216217
$this->failOnWarning = $failOnWarning;
217218
$this->stopOnDefect = $stopOnDefect;
218219
$this->stopOnDeprecation = $stopOnDeprecation;
220+
$this->specificDeprecationToStopOn = $specificDeprecationToStopOn;
219221
$this->stopOnError = $stopOnError;
220222
$this->stopOnFailure = $stopOnFailure;
221223
$this->stopOnIncomplete = $stopOnIncomplete;
@@ -1062,6 +1064,26 @@ public function stopOnDeprecation(): bool
10621064
return $this->stopOnDeprecation;
10631065
}
10641066

1067+
/**
1068+
* @phpstan-assert-if-true !null $this->specificDeprecationToStopOn
1069+
*/
1070+
public function hasSpecificDeprecationToStopOn(): bool
1071+
{
1072+
return $this->specificDeprecationToStopOn !== null;
1073+
}
1074+
1075+
/**
1076+
* @throws Exception
1077+
*/
1078+
public function specificDeprecationToStopOn(): string
1079+
{
1080+
if (!$this->hasSpecificDeprecationToStopOn()) {
1081+
throw new Exception;
1082+
}
1083+
1084+
return $this->specificDeprecationToStopOn;
1085+
}
1086+
10651087
/**
10661088
* @phpstan-assert-if-true !null $this->stopOnError
10671089
*/

src/TextUI/Configuration/Configuration.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
private bool $failOnWarning;
6464
private bool $stopOnDefect;
6565
private bool $stopOnDeprecation;
66+
private ?string $specificDeprecationToStopOn;
6667
private bool $stopOnError;
6768
private bool $stopOnFailure;
6869
private bool $stopOnIncomplete;
@@ -181,7 +182,7 @@
181182
* @param non-empty-list<non-empty-string> $testSuffixes
182183
* @param non-negative-int $shortenArraysForExportThreshold
183184
*/
184-
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 $displayDetailsOnPhpunitDeprecations, bool $displayDetailsOnTestsThatTriggerErrors, bool $displayDetailsOnTestsThatTriggerNotices, bool $displayDetailsOnTestsThatTriggerWarnings, bool $reverseDefectList, bool $requireCoverageMetadata, 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, bool $testDoxOutputSummary, ?array $testsCovering, ?array $testsUsing, ?array $testsRequiringPhpExtension, ?string $filter, ?string $excludeFilter, 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, int $shortenArraysForExportThreshold)
185+
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, ?string $specificDeprecationToStopOn, 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 $displayDetailsOnPhpunitDeprecations, bool $displayDetailsOnTestsThatTriggerErrors, bool $displayDetailsOnTestsThatTriggerNotices, bool $displayDetailsOnTestsThatTriggerWarnings, bool $reverseDefectList, bool $requireCoverageMetadata, 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, bool $testDoxOutputSummary, ?array $testsCovering, ?array $testsUsing, ?array $testsRequiringPhpExtension, ?string $filter, ?string $excludeFilter, 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, int $shortenArraysForExportThreshold)
185186
{
186187
$this->cliArguments = $cliArguments;
187188
$this->configurationFile = $configurationFile;
@@ -222,6 +223,7 @@ public function __construct(array $cliArguments, ?string $configurationFile, ?st
222223
$this->failOnWarning = $failOnWarning;
223224
$this->stopOnDefect = $stopOnDefect;
224225
$this->stopOnDeprecation = $stopOnDeprecation;
226+
$this->specificDeprecationToStopOn = $specificDeprecationToStopOn;
225227
$this->stopOnError = $stopOnError;
226228
$this->stopOnFailure = $stopOnFailure;
227229
$this->stopOnIncomplete = $stopOnIncomplete;
@@ -690,6 +692,26 @@ public function stopOnDeprecation(): bool
690692
return $this->stopOnDeprecation;
691693
}
692694

695+
/**
696+
* @phpstan-assert-if-true !null $this->specificDeprecationToStopOn
697+
*/
698+
public function hasSpecificDeprecationToStopOn(): bool
699+
{
700+
return $this->specificDeprecationToStopOn !== null;
701+
}
702+
703+
/**
704+
* @throws SpecificDeprecationToStopOnNotConfiguredException
705+
*/
706+
public function specificDeprecationToStopOn(): string
707+
{
708+
if (!$this->hasSpecificDeprecationToStopOn()) {
709+
throw new SpecificDeprecationToStopOnNotConfiguredException;
710+
}
711+
712+
return $this->specificDeprecationToStopOn;
713+
}
714+
693715
public function stopOnError(): bool
694716
{
695717
return $this->stopOnError;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <sebastian@phpunit.de>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\TextUI\Configuration;
11+
12+
use RuntimeException;
13+
14+
/**
15+
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
16+
*
17+
* @internal This class is not covered by the backward compatibility promise for PHPUnit
18+
*/
19+
final class SpecificDeprecationToStopOnNotConfiguredException extends RuntimeException implements Exception
20+
{
21+
}

0 commit comments

Comments
 (0)