Skip to content

Commit fb6673f

Browse files
Closes #5196
1 parent 6c7add2 commit fb6673f

26 files changed

+862
-417
lines changed

ChangeLog-10.1.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All notable changes of the PHPUnit 10.1 release series are documented in this fi
77
### Added
88

99
* [#5168](https://github.com/sebastianbergmann/phpunit/issues/5168): Allow test runner extensions to disable default progress and result printing
10+
* [#5196](https://github.com/sebastianbergmann/phpunit/issues/5196): Optionally (fail|stop) on (notice|deprecation) events
1011
* [#5201](https://github.com/sebastianbergmann/phpunit/issues/5201): Add `TestCase::registerFailureType()` to register interface that marks exceptions to be treated as failures, not errors
1112
* [#5231](https://github.com/sebastianbergmann/phpunit/pull/5231): `assertObjectHasProperty()` and `assertObjectNotHasProperty()`
1213
* [#5237](https://github.com/sebastianbergmann/phpunit/issues/5237): Implement `IgnoreClassForCodeCoverage`, `IgnoreMethodForCodeCoverage`, and `IgnoreFunctionForCodeCoverage` attributes

phpunit.xsd

+10-6
Original file line numberDiff line numberDiff line change
@@ -172,18 +172,22 @@
172172
<xs:attribute name="columns" type="columnsType" default="80"/>
173173
<xs:attribute name="requireCoverageMetadata" type="xs:boolean" default="false"/>
174174
<xs:attribute name="processIsolation" type="xs:boolean" default="false"/>
175+
<xs:attribute name="failOnDeprecation" type="xs:boolean" default="false"/>
176+
<xs:attribute name="failOnEmptyTestSuite" type="xs:boolean" default="false"/>
177+
<xs:attribute name="failOnIncomplete" type="xs:boolean" default="false"/>
178+
<xs:attribute name="failOnNotice" type="xs:boolean" default="false"/>
179+
<xs:attribute name="failOnRisky" type="xs:boolean" default="false"/>
180+
<xs:attribute name="failOnSkipped" type="xs:boolean" default="false"/>
181+
<xs:attribute name="failOnWarning" type="xs:boolean" default="false"/>
175182
<xs:attribute name="stopOnDefect" type="xs:boolean" default="false"/>
183+
<xs:attribute name="stopOnDeprecation" type="xs:boolean" default="false"/>
176184
<xs:attribute name="stopOnError" type="xs:boolean" default="false"/>
177185
<xs:attribute name="stopOnFailure" type="xs:boolean" default="false"/>
178-
<xs:attribute name="stopOnWarning" type="xs:boolean" default="false"/>
179186
<xs:attribute name="stopOnIncomplete" type="xs:boolean" default="false"/>
187+
<xs:attribute name="stopOnNotice" type="xs:boolean" default="false"/>
180188
<xs:attribute name="stopOnRisky" type="xs:boolean" default="false"/>
181189
<xs:attribute name="stopOnSkipped" type="xs:boolean" default="false"/>
182-
<xs:attribute name="failOnEmptyTestSuite" type="xs:boolean" default="false"/>
183-
<xs:attribute name="failOnIncomplete" type="xs:boolean" default="false"/>
184-
<xs:attribute name="failOnRisky" type="xs:boolean" default="false"/>
185-
<xs:attribute name="failOnSkipped" type="xs:boolean" default="false"/>
186-
<xs:attribute name="failOnWarning" type="xs:boolean" default="false"/>
190+
<xs:attribute name="stopOnWarning" type="xs:boolean" default="false"/>
187191
<xs:attribute name="beStrictAboutChangesToGlobalState" type="xs:boolean" default="false"/>
188192
<xs:attribute name="beStrictAboutOutputDuringTests" type="xs:boolean" default="false"/>
189193
<xs:attribute name="beStrictAboutTestsThatDoNotTestAnything" type="xs:boolean" default="true"/>

src/Framework/TestSuite.php

+16-41
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
use PHPUnit\Runner\Filter\Factory;
3939
use PHPUnit\Runner\PhptTestCase;
4040
use PHPUnit\Runner\TestSuiteLoader;
41-
use PHPUnit\TestRunner\TestResult\Facade;
41+
use PHPUnit\TestRunner\TestResult\Facade as TestResultFacade;
4242
use PHPUnit\TextUI\Configuration\Registry;
4343
use PHPUnit\Util\Filter;
4444
use PHPUnit\Util\Reflection;
@@ -69,13 +69,15 @@ class TestSuite implements IteratorAggregate, Reorderable, SelfDescribing, Test
6969
private array $tests = [];
7070
private ?array $providedTests = null;
7171
private ?Factory $iteratorFilter = null;
72+
private readonly bool $stopOnDefect;
73+
private readonly bool $stopOnDeprecation;
7274
private readonly bool $stopOnError;
7375
private readonly bool $stopOnFailure;
74-
private readonly bool $stopOnWarning;
75-
private readonly bool $stopOnRisky;
7676
private readonly bool $stopOnIncomplete;
77+
private readonly bool $stopOnNotice;
78+
private readonly bool $stopOnRisky;
7779
private readonly bool $stopOnSkipped;
78-
private readonly bool $stopOnDefect;
80+
private readonly bool $stopOnWarning;
7981

8082
public static function empty(string $name = null): static
8183
{
@@ -149,13 +151,15 @@ final private function __construct(string $name)
149151

150152
$configuration = Registry::get();
151153

152-
$this->stopOnError = $configuration->stopOnError();
153-
$this->stopOnFailure = $configuration->stopOnFailure();
154-
$this->stopOnWarning = $configuration->stopOnWarning();
155-
$this->stopOnRisky = $configuration->stopOnRisky();
156-
$this->stopOnIncomplete = $configuration->stopOnIncomplete();
157-
$this->stopOnSkipped = $configuration->stopOnSkipped();
158-
$this->stopOnDefect = $configuration->stopOnDefect();
154+
$this->stopOnDeprecation = $configuration->stopOnDeprecation();
155+
$this->stopOnDefect = $configuration->stopOnDefect();
156+
$this->stopOnError = $configuration->stopOnError();
157+
$this->stopOnFailure = $configuration->stopOnFailure();
158+
$this->stopOnIncomplete = $configuration->stopOnIncomplete();
159+
$this->stopOnNotice = $configuration->stopOnNotice();
160+
$this->stopOnRisky = $configuration->stopOnRisky();
161+
$this->stopOnSkipped = $configuration->stopOnSkipped();
162+
$this->stopOnWarning = $configuration->stopOnWarning();
159163
}
160164

161165
/**
@@ -344,7 +348,7 @@ public function run(): void
344348
}
345349

346350
foreach ($this as $test) {
347-
if ($this->shouldStop()) {
351+
if (TestResultFacade::shouldStop()) {
348352
break;
349353
}
350354

@@ -550,35 +554,6 @@ private function methodDoesNotExistOrIsDeclaredInTestCase(string $methodName): b
550554
$reflector->getMethod($methodName)->getDeclaringClass()->getName() === TestCase::class;
551555
}
552556

553-
private function shouldStop(): bool
554-
{
555-
if (($this->stopOnDefect || $this->stopOnError) && Facade::hasTestErroredEvents()) {
556-
return true;
557-
}
558-
559-
if (($this->stopOnDefect || $this->stopOnFailure) && Facade::hasTestFailedEvents()) {
560-
return true;
561-
}
562-
563-
if (($this->stopOnDefect || $this->stopOnWarning) && Facade::hasWarningEvents()) {
564-
return true;
565-
}
566-
567-
if (($this->stopOnDefect || $this->stopOnRisky) && Facade::hasTestConsideredRiskyEvents()) {
568-
return true;
569-
}
570-
571-
if ($this->stopOnSkipped && Facade::hasTestSkippedEvents()) {
572-
return true;
573-
}
574-
575-
if ($this->stopOnIncomplete && Facade::hasTestMarkedIncompleteEvents()) {
576-
return true;
577-
}
578-
579-
return false;
580-
}
581-
582557
/**
583558
* @throws Exception
584559
*/

src/Runner/TestResult/Collector.php

+14-13
Original file line numberDiff line numberDiff line change
@@ -229,19 +229,6 @@ public function hasTestMarkedIncompleteEvents(): bool
229229
return !empty($this->testMarkedIncompleteEvents);
230230
}
231231

232-
public function hasTestRunnerTriggeredWarningEvents(): bool
233-
{
234-
return !empty($this->testRunnerTriggeredWarningEvents);
235-
}
236-
237-
/**
238-
* @psalm-return list<TestRunnerWarningTriggered>
239-
*/
240-
public function testRunnerTriggeredWarningEvents(): array
241-
{
242-
return $this->testRunnerTriggeredWarningEvents;
243-
}
244-
245232
public function executionStarted(ExecutionStarted $event): void
246233
{
247234
$this->numberOfTests = $event->testSuite()->count();
@@ -470,6 +457,20 @@ public function testRunnerTriggeredWarning(TestRunnerWarningTriggered $event): v
470457
$this->testRunnerTriggeredWarningEvents[] = $event;
471458
}
472459

460+
public function hasDeprecationEvents(): bool
461+
{
462+
return !empty($this->testTriggeredDeprecationEvents) ||
463+
!empty($this->testTriggeredPhpDeprecationEvents) ||
464+
!empty($this->testTriggeredPhpunitDeprecationEvents) ||
465+
!empty($this->testRunnerTriggeredDeprecationEvents);
466+
}
467+
468+
public function hasNoticeEvents(): bool
469+
{
470+
return !empty($this->testTriggeredNoticeEvents) ||
471+
!empty($this->testTriggeredPhpNoticeEvents);
472+
}
473+
473474
public function hasWarningEvents(): bool
474475
{
475476
return !empty($this->testTriggeredWarningEvents) ||

src/Runner/TestResult/Facade.php

+33-42
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PHPUnit\Event\EventFacadeIsSealedException;
1313
use PHPUnit\Event\Facade as EventFacade;
1414
use PHPUnit\Event\UnknownSubscriberTypeException;
15+
use PHPUnit\TextUI\Configuration\Registry as ConfigurationRegistry;
1516

1617
/**
1718
* @internal This class is not covered by the backward compatibility promise for PHPUnit
@@ -42,54 +43,44 @@ public static function result(): TestResult
4243
* @throws EventFacadeIsSealedException
4344
* @throws UnknownSubscriberTypeException
4445
*/
45-
public static function hasTestErroredEvents(): bool
46+
public static function shouldStop(): bool
4647
{
47-
return self::collector()->hasTestErroredEvents();
48-
}
48+
$configuration = ConfigurationRegistry::get();
49+
$collector = self::collector();
4950

50-
/**
51-
* @throws EventFacadeIsSealedException
52-
* @throws UnknownSubscriberTypeException
53-
*/
54-
public static function hasTestFailedEvents(): bool
55-
{
56-
return self::collector()->hasTestFailedEvents();
57-
}
51+
if (($configuration->stopOnDefect() || $configuration->stopOnError()) && $collector->hasTestErroredEvents()) {
52+
return true;
53+
}
5854

59-
/**
60-
* @throws EventFacadeIsSealedException
61-
* @throws UnknownSubscriberTypeException
62-
*/
63-
public static function hasWarningEvents(): bool
64-
{
65-
return self::collector()->hasWarningEvents();
66-
}
55+
if (($configuration->stopOnDefect() || $configuration->stopOnFailure()) && $collector->hasTestFailedEvents()) {
56+
return true;
57+
}
6758

68-
/**
69-
* @throws EventFacadeIsSealedException
70-
* @throws UnknownSubscriberTypeException
71-
*/
72-
public static function hasTestConsideredRiskyEvents(): bool
73-
{
74-
return self::collector()->hasTestConsideredRiskyEvents();
75-
}
59+
if (($configuration->stopOnDefect() || $configuration->stopOnWarning()) && $collector->hasWarningEvents()) {
60+
return true;
61+
}
7662

77-
/**
78-
* @throws EventFacadeIsSealedException
79-
* @throws UnknownSubscriberTypeException
80-
*/
81-
public static function hasTestSkippedEvents(): bool
82-
{
83-
return self::collector()->hasTestSkippedEvents();
84-
}
63+
if (($configuration->stopOnDefect() || $configuration->stopOnRisky()) && $collector->hasTestConsideredRiskyEvents()) {
64+
return true;
65+
}
8566

86-
/**
87-
* @throws EventFacadeIsSealedException
88-
* @throws UnknownSubscriberTypeException
89-
*/
90-
public static function hasTestMarkedIncompleteEvents(): bool
91-
{
92-
return self::collector()->hasTestMarkedIncompleteEvents();
67+
if ($configuration->stopOnDeprecation() && $collector->hasDeprecationEvents()) {
68+
return true;
69+
}
70+
71+
if ($configuration->stopOnNotice() && $collector->hasNoticeEvents()) {
72+
return true;
73+
}
74+
75+
if ($configuration->stopOnIncomplete() && $collector->hasTestMarkedIncompleteEvents()) {
76+
return true;
77+
}
78+
79+
if ($configuration->stopOnSkipped() && $collector->hasTestSkippedEvents()) {
80+
return true;
81+
}
82+
83+
return false;
9384
}
9485

9586
/**

src/TextUI/Application.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,13 @@ public function run(array $argv): int
195195
CodeCoverage::instance()->generateReports($printer, $configuration);
196196

197197
$shellExitCode = (new ShellExitCodeCalculator)->calculate(
198+
$configuration->failOnDeprecation(),
198199
$configuration->failOnEmptyTestSuite(),
199-
$configuration->failOnRisky(),
200-
$configuration->failOnWarning(),
201200
$configuration->failOnIncomplete(),
201+
$configuration->failOnNotice(),
202+
$configuration->failOnRisky(),
202203
$configuration->failOnSkipped(),
204+
$configuration->failOnWarning(),
203205
$result
204206
);
205207

0 commit comments

Comments
 (0)