Skip to content

Commit 94cbc3a

Browse files
Closes #6100
1 parent a4f17fb commit 94cbc3a

File tree

6 files changed

+112
-3
lines changed

6 files changed

+112
-3
lines changed

ChangeLog-11.5.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ All notable changes of the PHPUnit 11.5 release series are documented in this fi
1414
* [#6095](https://github.com/sebastianbergmann/phpunit/issues/6095): Expectation is not counted correctly when a doubled method is called more often than is expected
1515
* [#6096](https://github.com/sebastianbergmann/phpunit/issues/6096): `--list-tests-xml` is broken when a group with a numeric name is defined
1616
* [#6098](https://github.com/sebastianbergmann/phpunit/issues/6098): No `system-out` element in JUnit XML logfile
17+
* [#6100](https://github.com/sebastianbergmann/phpunit/issues/6100): Suppressed deprecations incorrectly stop test execution when execution should be stopped on deprecation
1718

1819
## [11.5.2] - 2024-12-21
1920

src/Runner/DeprecationCollector/Collector.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use PHPUnit\Event\Facade;
1414
use PHPUnit\Event\Test\DeprecationTriggered;
1515
use PHPUnit\Event\UnknownSubscriberTypeException;
16+
use PHPUnit\TestRunner\IssueFilter;
1617

1718
/**
1819
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
@@ -21,21 +22,30 @@
2122
*/
2223
final class Collector
2324
{
25+
private readonly IssueFilter $issueFilter;
26+
2427
/**
2528
* @var list<non-empty-string>
2629
*/
2730
private array $deprecations = [];
2831

32+
/**
33+
* @var list<non-empty-string>
34+
*/
35+
private array $filteredDeprecations = [];
36+
2937
/**
3038
* @throws EventFacadeIsSealedException
3139
* @throws UnknownSubscriberTypeException
3240
*/
33-
public function __construct(Facade $facade)
41+
public function __construct(Facade $facade, IssueFilter $issueFilter)
3442
{
3543
$facade->registerSubscribers(
3644
new TestPreparedSubscriber($this),
3745
new TestTriggeredDeprecationSubscriber($this),
3846
);
47+
48+
$this->issueFilter = $issueFilter;
3949
}
4050

4151
/**
@@ -46,6 +56,14 @@ public function deprecations(): array
4656
return $this->deprecations;
4757
}
4858

59+
/**
60+
* @return list<non-empty-string>
61+
*/
62+
public function filteredDeprecations(): array
63+
{
64+
return $this->filteredDeprecations;
65+
}
66+
4967
public function testPrepared(): void
5068
{
5169
$this->deprecations = [];
@@ -54,5 +72,11 @@ public function testPrepared(): void
5472
public function testTriggeredDeprecation(DeprecationTriggered $event): void
5573
{
5674
$this->deprecations[] = $event->message();
75+
76+
if (!$this->issueFilter->shouldBeProcessed($event)) {
77+
return;
78+
}
79+
80+
$this->filteredDeprecations[] = $event->message();
5781
}
5882
}

src/Runner/DeprecationCollector/Facade.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use PHPUnit\Event\EventFacadeIsSealedException;
1313
use PHPUnit\Event\Facade as EventFacade;
1414
use PHPUnit\Event\UnknownSubscriberTypeException;
15+
use PHPUnit\TestRunner\IssueFilter;
16+
use PHPUnit\TextUI\Configuration\Registry as ConfigurationRegistry;
1517

1618
/**
1719
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
@@ -42,14 +44,30 @@ public static function deprecations(): array
4244
return self::collector()->deprecations();
4345
}
4446

47+
/**
48+
* @throws EventFacadeIsSealedException
49+
* @throws UnknownSubscriberTypeException
50+
*
51+
* @return list<non-empty-string>
52+
*/
53+
public static function filteredDeprecations(): array
54+
{
55+
return self::collector()->filteredDeprecations();
56+
}
57+
4558
/**
4659
* @throws EventFacadeIsSealedException
4760
* @throws UnknownSubscriberTypeException
4861
*/
4962
private static function collector(): Collector
5063
{
5164
if (self::$collector === null) {
52-
self::$collector = new Collector(EventFacade::instance());
65+
self::$collector = new Collector(
66+
EventFacade::instance(),
67+
new IssueFilter(
68+
ConfigurationRegistry::get()->source(),
69+
),
70+
);
5371
}
5472

5573
return self::$collector;

src/Runner/TestResult/Facade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private static function stopOnDeprecation(Configuration $configuration): bool
113113
return false;
114114
}
115115

116-
$deprecations = DeprecationCollectorFacade::deprecations();
116+
$deprecations = DeprecationCollectorFacade::filteredDeprecations();
117117

118118
if (!$configuration->hasSpecificDeprecationToStopOn()) {
119119
return $deprecations !== [];

tests/end-to-end/regression/6100.phpt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--TEST--
2+
https://github.com/sebastianbergmann/phpunit/issues/6100
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--no-configuration';
7+
$_SERVER['argv'][] = '--fail-on-deprecation';
8+
$_SERVER['argv'][] = '--stop-on-deprecation';
9+
$_SERVER['argv'][] = '--debug';
10+
$_SERVER['argv'][] = __DIR__ . '/6100/Issue6100Test.php';
11+
12+
require_once __DIR__ . '/../../bootstrap.php';
13+
14+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
15+
--EXPECTF--
16+
PHPUnit Started (PHPUnit %s using %s)
17+
Test Runner Configured
18+
Event Facade Sealed
19+
Test Suite Loaded (2 tests)
20+
Test Runner Started
21+
Test Suite Sorted
22+
Test Runner Execution Started (2 tests)
23+
Test Suite Started (PHPUnit\TestFixture\Issue6100\Issue6100Test, 2 tests)
24+
Test Preparation Started (PHPUnit\TestFixture\Issue6100\Issue6100Test::testOne)
25+
Test Prepared (PHPUnit\TestFixture\Issue6100\Issue6100Test::testOne)
26+
Test Triggered Deprecation (PHPUnit\TestFixture\Issue6100\Issue6100Test::testOne, unknown if issue was triggered in first-party code or third-party code, suppressed using operator)
27+
test
28+
Test Passed (PHPUnit\TestFixture\Issue6100\Issue6100Test::testOne)
29+
Test Finished (PHPUnit\TestFixture\Issue6100\Issue6100Test::testOne)
30+
Test Preparation Started (PHPUnit\TestFixture\Issue6100\Issue6100Test::testTwo)
31+
Test Prepared (PHPUnit\TestFixture\Issue6100\Issue6100Test::testTwo)
32+
Test Passed (PHPUnit\TestFixture\Issue6100\Issue6100Test::testTwo)
33+
Test Finished (PHPUnit\TestFixture\Issue6100\Issue6100Test::testTwo)
34+
Test Suite Finished (PHPUnit\TestFixture\Issue6100\Issue6100Test, 2 tests)
35+
Test Runner Execution Finished
36+
Test Runner Finished
37+
PHPUnit Finished (Shell Exit Code: 0)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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\TestFixture\Issue6100;
11+
12+
use const E_USER_DEPRECATED;
13+
use function trigger_error;
14+
use PHPUnit\Framework\TestCase;
15+
16+
final class Issue6100Test extends TestCase
17+
{
18+
public function testOne(): void
19+
{
20+
@trigger_error('test', E_USER_DEPRECATED);
21+
22+
$this->assertTrue(true);
23+
}
24+
25+
public function testTwo(): void
26+
{
27+
$this->assertTrue(true);
28+
}
29+
}

0 commit comments

Comments
 (0)