Skip to content

Commit

Permalink
Closes #6100
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jan 10, 2025
1 parent a4f17fb commit 94cbc3a
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 3 deletions.
1 change: 1 addition & 0 deletions ChangeLog-11.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ All notable changes of the PHPUnit 11.5 release series are documented in this fi
* [#6095](https://github.com/sebastianbergmann/phpunit/issues/6095): Expectation is not counted correctly when a doubled method is called more often than is expected
* [#6096](https://github.com/sebastianbergmann/phpunit/issues/6096): `--list-tests-xml` is broken when a group with a numeric name is defined
* [#6098](https://github.com/sebastianbergmann/phpunit/issues/6098): No `system-out` element in JUnit XML logfile
* [#6100](https://github.com/sebastianbergmann/phpunit/issues/6100): Suppressed deprecations incorrectly stop test execution when execution should be stopped on deprecation

## [11.5.2] - 2024-12-21

Expand Down
26 changes: 25 additions & 1 deletion src/Runner/DeprecationCollector/Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use PHPUnit\Event\Facade;
use PHPUnit\Event\Test\DeprecationTriggered;
use PHPUnit\Event\UnknownSubscriberTypeException;
use PHPUnit\TestRunner\IssueFilter;

/**
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
Expand All @@ -21,21 +22,30 @@
*/
final class Collector
{
private readonly IssueFilter $issueFilter;

/**
* @var list<non-empty-string>
*/
private array $deprecations = [];

/**
* @var list<non-empty-string>
*/
private array $filteredDeprecations = [];

/**
* @throws EventFacadeIsSealedException
* @throws UnknownSubscriberTypeException
*/
public function __construct(Facade $facade)
public function __construct(Facade $facade, IssueFilter $issueFilter)
{
$facade->registerSubscribers(
new TestPreparedSubscriber($this),
new TestTriggeredDeprecationSubscriber($this),
);

$this->issueFilter = $issueFilter;
}

/**
Expand All @@ -46,6 +56,14 @@ public function deprecations(): array
return $this->deprecations;
}

/**
* @return list<non-empty-string>
*/
public function filteredDeprecations(): array
{
return $this->filteredDeprecations;
}

public function testPrepared(): void
{
$this->deprecations = [];
Expand All @@ -54,5 +72,11 @@ public function testPrepared(): void
public function testTriggeredDeprecation(DeprecationTriggered $event): void
{
$this->deprecations[] = $event->message();

if (!$this->issueFilter->shouldBeProcessed($event)) {
return;
}

$this->filteredDeprecations[] = $event->message();
}
}
20 changes: 19 additions & 1 deletion src/Runner/DeprecationCollector/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use PHPUnit\Event\EventFacadeIsSealedException;
use PHPUnit\Event\Facade as EventFacade;
use PHPUnit\Event\UnknownSubscriberTypeException;
use PHPUnit\TestRunner\IssueFilter;
use PHPUnit\TextUI\Configuration\Registry as ConfigurationRegistry;

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

/**
* @throws EventFacadeIsSealedException
* @throws UnknownSubscriberTypeException
*
* @return list<non-empty-string>
*/
public static function filteredDeprecations(): array
{
return self::collector()->filteredDeprecations();
}

/**
* @throws EventFacadeIsSealedException
* @throws UnknownSubscriberTypeException
*/
private static function collector(): Collector
{
if (self::$collector === null) {
self::$collector = new Collector(EventFacade::instance());
self::$collector = new Collector(
EventFacade::instance(),
new IssueFilter(
ConfigurationRegistry::get()->source(),
),
);
}

return self::$collector;
Expand Down
2 changes: 1 addition & 1 deletion src/Runner/TestResult/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private static function stopOnDeprecation(Configuration $configuration): bool
return false;
}

$deprecations = DeprecationCollectorFacade::deprecations();
$deprecations = DeprecationCollectorFacade::filteredDeprecations();

if (!$configuration->hasSpecificDeprecationToStopOn()) {
return $deprecations !== [];
Expand Down
37 changes: 37 additions & 0 deletions tests/end-to-end/regression/6100.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/issues/6100
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--fail-on-deprecation';
$_SERVER['argv'][] = '--stop-on-deprecation';
$_SERVER['argv'][] = '--debug';
$_SERVER['argv'][] = __DIR__ . '/6100/Issue6100Test.php';

require_once __DIR__ . '/../../bootstrap.php';

(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
--EXPECTF--
PHPUnit Started (PHPUnit %s using %s)
Test Runner Configured
Event Facade Sealed
Test Suite Loaded (2 tests)
Test Runner Started
Test Suite Sorted
Test Runner Execution Started (2 tests)
Test Suite Started (PHPUnit\TestFixture\Issue6100\Issue6100Test, 2 tests)
Test Preparation Started (PHPUnit\TestFixture\Issue6100\Issue6100Test::testOne)
Test Prepared (PHPUnit\TestFixture\Issue6100\Issue6100Test::testOne)
Test Triggered Deprecation (PHPUnit\TestFixture\Issue6100\Issue6100Test::testOne, unknown if issue was triggered in first-party code or third-party code, suppressed using operator)
test
Test Passed (PHPUnit\TestFixture\Issue6100\Issue6100Test::testOne)
Test Finished (PHPUnit\TestFixture\Issue6100\Issue6100Test::testOne)
Test Preparation Started (PHPUnit\TestFixture\Issue6100\Issue6100Test::testTwo)
Test Prepared (PHPUnit\TestFixture\Issue6100\Issue6100Test::testTwo)
Test Passed (PHPUnit\TestFixture\Issue6100\Issue6100Test::testTwo)
Test Finished (PHPUnit\TestFixture\Issue6100\Issue6100Test::testTwo)
Test Suite Finished (PHPUnit\TestFixture\Issue6100\Issue6100Test, 2 tests)
Test Runner Execution Finished
Test Runner Finished
PHPUnit Finished (Shell Exit Code: 0)
29 changes: 29 additions & 0 deletions tests/end-to-end/regression/6100/Issue6100Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\TestFixture\Issue6100;

use const E_USER_DEPRECATED;
use function trigger_error;
use PHPUnit\Framework\TestCase;

final class Issue6100Test extends TestCase
{
public function testOne(): void
{
@trigger_error('test', E_USER_DEPRECATED);

$this->assertTrue(true);
}

public function testTwo(): void
{
$this->assertTrue(true);
}
}

0 comments on commit 94cbc3a

Please sign in to comment.