Skip to content

Commit c4fa2c3

Browse files
Closes #6236
1 parent 3eab204 commit c4fa2c3

File tree

47 files changed

+357
-108
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+357
-108
lines changed

ChangeLog-10.5.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ All notable changes of the PHPUnit 10.5 release series are documented in this fi
66

77
### Added
88

9-
* [#6239](https://github.com/sebastianbergmann/phpunit/issues/6239): `--do-not-fail-on-deprecation`, `--do-not-fail-on-phpunit-deprecation`, `--do-not-fail-on-empty-test-suite`, `--do-not-fail-on-incomplete`, `--do-not-fail-on-notice`, `--do-not-fail-on-risky`, `--do-not-fail-on-skipped`, and `--do-not-fail-on-warning` CLI options
9+
* [#6236](https://github.com/sebastianbergmann/phpunit/issues/6236): `failOnPhpunitWarning` attribute on the `<phpunit>` element of the XML configuration file and `--fail-on-phpunit-warning` CLI option for controlling whether PHPUnit should fail on PHPUnit warnings (default: `true`)
10+
* [#6239](https://github.com/sebastianbergmann/phpunit/issues/6239): `--do-not-fail-on-deprecation`, `--do-not-fail-on-phpunit-warning`, --do-not-fail-on-phpunit-deprecation`, `--do-not-fail-on-empty-test-suite`, `--do-not-fail-on-incomplete`, `--do-not-fail-on-notice`, `--do-not-fail-on-risky`, `--do-not-fail-on-skipped`, and `--do-not-fail-on-warning` CLI options
1011
* `--do-not-report-useless-tests` CLI option as a replacement for `--dont-report-useless-tests`
1112

1213
### Deprecated

phpunit.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
<xs:attribute name="failOnAllIssues" type="xs:boolean" default="false"/>
181181
<xs:attribute name="failOnDeprecation" type="xs:boolean" default="false"/>
182182
<xs:attribute name="failOnPhpunitDeprecation" type="xs:boolean" default="false"/>
183+
<xs:attribute name="failOnPhpunitWarning" type="xs:boolean" default="true"/>
183184
<xs:attribute name="failOnEmptyTestSuite" type="xs:boolean" default="false"/>
184185
<xs:attribute name="failOnIncomplete" type="xs:boolean" default="false"/>
185186
<xs:attribute name="failOnNotice" type="xs:boolean" default="false"/>

src/Runner/TestResult/TestResult.php

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -387,32 +387,32 @@ public function hasTestRunnerTriggeredWarningEvents(): bool
387387
}
388388

389389
public function wasSuccessful(): bool
390-
{
391-
return $this->wasSuccessfulIgnoringPhpunitWarnings() &&
392-
!$this->hasTestTriggeredPhpunitErrorEvents() &&
393-
!$this->hasTestRunnerTriggeredWarningEvents() &&
394-
!$this->hasTestTriggeredPhpunitWarningEvents();
395-
}
396-
397-
public function wasSuccessfulIgnoringPhpunitWarnings(): bool
398390
{
399391
return !$this->hasTestErroredEvents() &&
400-
!$this->hasTestFailedEvents();
392+
!$this->hasTestFailedEvents() &&
393+
!$this->hasTestTriggeredPhpunitErrorEvents();
401394
}
402395

403396
public function wasSuccessfulAndNoTestHasIssues(): bool
404397
{
405398
return $this->wasSuccessful() && !$this->hasTestsWithIssues();
406399
}
407400

401+
public function hasIssues(): bool
402+
{
403+
return $this->hasTestsWithIssues() ||
404+
$this->hasTestRunnerTriggeredWarningEvents();
405+
}
406+
408407
public function hasTestsWithIssues(): bool
409408
{
410409
return $this->hasRiskyTests() ||
411410
$this->hasIncompleteTests() ||
412411
$this->hasDeprecations() ||
413412
!empty($this->errors) ||
414413
$this->hasNotices() ||
415-
$this->hasWarnings();
414+
$this->hasWarnings() ||
415+
$this->hasPhpunitWarnings();
416416
}
417417

418418
/**
@@ -515,6 +515,17 @@ public function numberOfPhpunitDeprecations(): int
515515
count($this->testRunnerTriggeredDeprecationEvents);
516516
}
517517

518+
public function hasPhpunitWarnings(): bool
519+
{
520+
return $this->numberOfPhpunitWarnings() > 0;
521+
}
522+
523+
public function numberOfPhpunitWarnings(): int
524+
{
525+
return count($this->testTriggeredPhpunitWarningEvents) +
526+
count($this->testRunnerTriggeredWarningEvents);
527+
}
528+
518529
public function numberOfDeprecations(): int
519530
{
520531
return count($this->deprecations) +
@@ -542,9 +553,7 @@ public function hasWarnings(): bool
542553
public function numberOfWarnings(): int
543554
{
544555
return count($this->warnings) +
545-
count($this->phpWarnings) +
546-
count($this->testTriggeredPhpunitWarningEvents) +
547-
count($this->testRunnerTriggeredWarningEvents);
556+
count($this->phpWarnings);
548557
}
549558

550559
public function hasIncompleteTests(): bool

src/TextUI/Configuration/Cli/Builder.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ final class Builder
106106
'fail-on-all-issues',
107107
'fail-on-deprecation',
108108
'fail-on-phpunit-deprecation',
109+
'fail-on-phpunit-warning',
109110
'fail-on-empty-test-suite',
110111
'fail-on-incomplete',
111112
'fail-on-notice',
@@ -114,6 +115,7 @@ final class Builder
114115
'fail-on-warning',
115116
'do-not-fail-on-deprecation',
116117
'do-not-fail-on-phpunit-deprecation',
118+
'do-not-fail-on-phpunit-warning',
117119
'do-not-fail-on-empty-test-suite',
118120
'do-not-fail-on-incomplete',
119121
'do-not-fail-on-notice',
@@ -213,6 +215,7 @@ public function fromParameters(array $parameters): Configuration
213215
$failOnAllIssues = null;
214216
$failOnDeprecation = null;
215217
$failOnPhpunitDeprecation = null;
218+
$failOnPhpunitWarning = null;
216219
$failOnEmptyTestSuite = null;
217220
$failOnIncomplete = null;
218221
$failOnNotice = null;
@@ -221,6 +224,7 @@ public function fromParameters(array $parameters): Configuration
221224
$failOnWarning = null;
222225
$doNotFailOnDeprecation = null;
223226
$doNotFailOnPhpunitDeprecation = null;
227+
$doNotFailOnPhpunitWarning = null;
224228
$doNotFailOnEmptyTestSuite = null;
225229
$doNotFailOnIncomplete = null;
226230
$doNotFailOnNotice = null;
@@ -616,6 +620,17 @@ public function fromParameters(array $parameters): Configuration
616620

617621
break;
618622

623+
case '--fail-on-phpunit-warning':
624+
$this->warnWhenOptionsConflict(
625+
$doNotFailOnPhpunitWarning,
626+
'--fail-on-phpunit-warning',
627+
'--do-not-fail-on-phpunit-warning',
628+
);
629+
630+
$failOnPhpunitWarning = true;
631+
632+
break;
633+
619634
case '--fail-on-empty-test-suite':
620635
$this->warnWhenOptionsConflict(
621636
$doNotFailOnEmptyTestSuite,
@@ -704,6 +719,17 @@ public function fromParameters(array $parameters): Configuration
704719

705720
break;
706721

722+
case '--do-not-fail-on-phpunit-warning':
723+
$this->warnWhenOptionsConflict(
724+
$failOnPhpunitWarning,
725+
'--do-not-fail-on-phpunit-warning',
726+
'--fail-on-phpunit-warning',
727+
);
728+
729+
$doNotFailOnPhpunitWarning = true;
730+
731+
break;
732+
707733
case '--do-not-fail-on-empty-test-suite':
708734
$this->warnWhenOptionsConflict(
709735
$failOnEmptyTestSuite,
@@ -1095,6 +1121,7 @@ public function fromParameters(array $parameters): Configuration
10951121
$failOnAllIssues,
10961122
$failOnDeprecation,
10971123
$failOnPhpunitDeprecation,
1124+
$failOnPhpunitWarning,
10981125
$failOnEmptyTestSuite,
10991126
$failOnIncomplete,
11001127
$failOnNotice,
@@ -1103,6 +1130,7 @@ public function fromParameters(array $parameters): Configuration
11031130
$failOnWarning,
11041131
$doNotFailOnDeprecation,
11051132
$doNotFailOnPhpunitDeprecation,
1133+
$doNotFailOnPhpunitWarning,
11061134
$doNotFailOnEmptyTestSuite,
11071135
$doNotFailOnIncomplete,
11081136
$doNotFailOnNotice,

src/TextUI/Configuration/Cli/Configuration.php

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ final class Configuration
5757
private readonly ?bool $failOnAllIssues;
5858
private readonly ?bool $failOnDeprecation;
5959
private readonly ?bool $failOnPhpunitDeprecation;
60+
private readonly ?bool $failOnPhpunitWarning;
6061
private readonly ?bool $failOnEmptyTestSuite;
6162
private readonly ?bool $failOnIncomplete;
6263
private readonly ?bool $failOnNotice;
@@ -65,6 +66,7 @@ final class Configuration
6566
private readonly ?bool $failOnWarning;
6667
private readonly ?bool $doNotFailOnDeprecation;
6768
private readonly ?bool $doNotFailOnPhpunitDeprecation;
69+
private readonly ?bool $doNotFailOnPhpunitWarning;
6870
private readonly ?bool $doNotFailOnEmptyTestSuite;
6971
private readonly ?bool $doNotFailOnIncomplete;
7072
private readonly ?bool $doNotFailOnNotice;
@@ -140,7 +142,7 @@ final class Configuration
140142
* @psalm-param list<non-empty-string> $arguments
141143
* @psalm-param ?non-empty-list<non-empty-string> $testSuffixes
142144
*/
143-
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 $failOnAllIssues, ?bool $failOnDeprecation, ?bool $failOnPhpunitDeprecation, ?bool $failOnEmptyTestSuite, ?bool $failOnIncomplete, ?bool $failOnNotice, ?bool $failOnRisky, ?bool $failOnSkipped, ?bool $failOnWarning, ?bool $doNotFailOnDeprecation, ?bool $doNotFailOnPhpunitDeprecation, ?bool $doNotFailOnEmptyTestSuite, ?bool $doNotFailOnIncomplete, ?bool $doNotFailOnNotice, ?bool $doNotFailOnRisky, ?bool $doNotFailOnSkipped, ?bool $doNotFailOnWarning, ?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 $displayDetailsOnAllIssues, ?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 $printerTestDox, bool $debug)
145+
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 $failOnAllIssues, ?bool $failOnDeprecation, ?bool $failOnPhpunitDeprecation, ?bool $failOnPhpunitWarning, ?bool $failOnEmptyTestSuite, ?bool $failOnIncomplete, ?bool $failOnNotice, ?bool $failOnRisky, ?bool $failOnSkipped, ?bool $failOnWarning, ?bool $doNotFailOnDeprecation, ?bool $doNotFailOnPhpunitDeprecation, ?bool $doNotFailOnPhpunitWarning, ?bool $doNotFailOnEmptyTestSuite, ?bool $doNotFailOnIncomplete, ?bool $doNotFailOnNotice, ?bool $doNotFailOnRisky, ?bool $doNotFailOnSkipped, ?bool $doNotFailOnWarning, ?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 $displayDetailsOnAllIssues, ?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 $printerTestDox, bool $debug)
144146
{
145147
$this->arguments = $arguments;
146148
$this->atLeastVersion = $atLeastVersion;
@@ -178,6 +180,7 @@ public function __construct(array $arguments, ?string $atLeastVersion, ?bool $ba
178180
$this->failOnAllIssues = $failOnAllIssues;
179181
$this->failOnDeprecation = $failOnDeprecation;
180182
$this->failOnPhpunitDeprecation = $failOnPhpunitDeprecation;
183+
$this->failOnPhpunitWarning = $failOnPhpunitWarning;
181184
$this->failOnEmptyTestSuite = $failOnEmptyTestSuite;
182185
$this->failOnIncomplete = $failOnIncomplete;
183186
$this->failOnNotice = $failOnNotice;
@@ -186,6 +189,7 @@ public function __construct(array $arguments, ?string $atLeastVersion, ?bool $ba
186189
$this->failOnWarning = $failOnWarning;
187190
$this->doNotFailOnDeprecation = $doNotFailOnDeprecation;
188191
$this->doNotFailOnPhpunitDeprecation = $doNotFailOnPhpunitDeprecation;
192+
$this->doNotFailOnPhpunitWarning = $doNotFailOnPhpunitWarning;
189193
$this->doNotFailOnEmptyTestSuite = $doNotFailOnEmptyTestSuite;
190194
$this->doNotFailOnIncomplete = $doNotFailOnIncomplete;
191195
$this->doNotFailOnNotice = $doNotFailOnNotice;
@@ -940,6 +944,26 @@ public function failOnPhpunitDeprecation(): bool
940944
return $this->failOnPhpunitDeprecation;
941945
}
942946

947+
/**
948+
* @psalm-assert-if-true !null $this->failOnPhpunitWarning
949+
*/
950+
public function hasFailOnPhpunitWarning(): bool
951+
{
952+
return $this->failOnPhpunitWarning !== null;
953+
}
954+
955+
/**
956+
* @throws Exception
957+
*/
958+
public function failOnPhpunitWarning(): bool
959+
{
960+
if (!$this->hasFailOnPhpunitWarning()) {
961+
throw new Exception;
962+
}
963+
964+
return $this->failOnPhpunitWarning;
965+
}
966+
943967
/**
944968
* @psalm-assert-if-true !null $this->failOnEmptyTestSuite
945969
*/
@@ -1100,6 +1124,26 @@ public function doNotFailOnPhpunitDeprecation(): bool
11001124
return $this->doNotFailOnPhpunitDeprecation;
11011125
}
11021126

1127+
/**
1128+
* @psalm-assert-if-true !null $this->doNotFailOnPhpunitWarning
1129+
*/
1130+
public function hasDoNotFailOnPhpunitWarning(): bool
1131+
{
1132+
return $this->doNotFailOnPhpunitWarning !== null;
1133+
}
1134+
1135+
/**
1136+
* @throws Exception
1137+
*/
1138+
public function doNotFailOnPhpunitWarning(): bool
1139+
{
1140+
if (!$this->hasDoNotFailOnPhpunitWarning()) {
1141+
throw new Exception;
1142+
}
1143+
1144+
return $this->doNotFailOnPhpunitWarning;
1145+
}
1146+
11031147
/**
11041148
* @psalm-assert-if-true !null $this->doNotFailOnEmptyTestSuite
11051149
*/

0 commit comments

Comments
 (0)