Skip to content

Commit bb29d35

Browse files
committed
feature #54593 [PhpUnitBridge] Add ExpectUserDeprecationMessageTrait (derrabus)
This PR was merged into the 7.2 branch. Discussion ---------- [PhpUnitBridge] Add `ExpectUserDeprecationMessageTrait` | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | Part of #49069, replaces #54538 | License | MIT PHPUnit 11 introduces a method `expectUserDeprecationMessage()` which lets us define which deprecation messages we expect the tested code to raise. This new method can replace our own `expectDeprecation()` method once we upgrade to PHPUnit 11. This PR introduces a `ExpectUserDeprecationMessageTrait` that polyfills this method for older PHPUnit versions. This allowed me to run all tests that I've migrated to `expectUserDeprecationMessage()` with PHPUnit 11. Commits ------- 2485e15d9d [PhpUnitBridge] Add ExpectUserDeprecationMessageTrait
2 parents c41d35b + 4206fc0 commit bb29d35

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

Tests/Generator/Dumper/CompiledUrlGeneratorDumperTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Component\Routing\Tests\Generator\Dumper;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
15+
use Symfony\Bridge\PhpUnit\ExpectUserDeprecationMessageTrait;
1616
use Symfony\Component\Routing\Exception\RouteCircularReferenceException;
1717
use Symfony\Component\Routing\Exception\RouteNotFoundException;
1818
use Symfony\Component\Routing\Generator\CompiledUrlGenerator;
@@ -24,7 +24,7 @@
2424

2525
class CompiledUrlGeneratorDumperTest extends TestCase
2626
{
27-
use ExpectDeprecationTrait;
27+
use ExpectUserDeprecationMessageTrait;
2828

2929
private RouteCollection $routeCollection;
3030
private CompiledUrlGeneratorDumper $generatorDumper;
@@ -347,7 +347,7 @@ public function testIndirectCircularReferenceShouldThrowAnException()
347347
*/
348348
public function testDeprecatedAlias()
349349
{
350-
$this->expectDeprecation('Since foo/bar 1.0.0: The "b" route alias is deprecated. You should stop using it, as it will be removed in the future.');
350+
$this->expectUserDeprecationMessage('Since foo/bar 1.0.0: The "b" route alias is deprecated. You should stop using it, as it will be removed in the future.');
351351

352352
$this->routeCollection->add('a', new Route('/foo'));
353353
$this->routeCollection->addAlias('b', 'a')
@@ -365,7 +365,7 @@ public function testDeprecatedAlias()
365365
*/
366366
public function testDeprecatedAliasWithCustomMessage()
367367
{
368-
$this->expectDeprecation('Since foo/bar 1.0.0: foo b.');
368+
$this->expectUserDeprecationMessage('Since foo/bar 1.0.0: foo b.');
369369

370370
$this->routeCollection->add('a', new Route('/foo'));
371371
$this->routeCollection->addAlias('b', 'a')
@@ -383,7 +383,7 @@ public function testDeprecatedAliasWithCustomMessage()
383383
*/
384384
public function testTargettingADeprecatedAliasShouldTriggerDeprecation()
385385
{
386-
$this->expectDeprecation('Since foo/bar 1.0.0: foo b.');
386+
$this->expectUserDeprecationMessage('Since foo/bar 1.0.0: foo b.');
387387

388388
$this->routeCollection->add('a', new Route('/foo'));
389389
$this->routeCollection->addAlias('b', 'a')

Tests/Generator/UrlGeneratorTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Psr\Log\LoggerInterface;
16-
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
16+
use Symfony\Bridge\PhpUnit\ExpectUserDeprecationMessageTrait;
1717
use Symfony\Component\Routing\Exception\InvalidParameterException;
1818
use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
1919
use Symfony\Component\Routing\Exception\RouteCircularReferenceException;
@@ -26,7 +26,7 @@
2626

2727
class UrlGeneratorTest extends TestCase
2828
{
29-
use ExpectDeprecationTrait;
29+
use ExpectUserDeprecationMessageTrait;
3030

3131
public function testAbsoluteUrlWithPort80()
3232
{
@@ -811,7 +811,7 @@ public function testAliasWhichTargetRouteDoesntExist()
811811
*/
812812
public function testDeprecatedAlias()
813813
{
814-
$this->expectDeprecation('Since foo/bar 1.0.0: The "b" route alias is deprecated. You should stop using it, as it will be removed in the future.');
814+
$this->expectUserDeprecationMessage('Since foo/bar 1.0.0: The "b" route alias is deprecated. You should stop using it, as it will be removed in the future.');
815815

816816
$routes = new RouteCollection();
817817
$routes->add('a', new Route('/foo'));
@@ -826,7 +826,7 @@ public function testDeprecatedAlias()
826826
*/
827827
public function testDeprecatedAliasWithCustomMessage()
828828
{
829-
$this->expectDeprecation('Since foo/bar 1.0.0: foo b.');
829+
$this->expectUserDeprecationMessage('Since foo/bar 1.0.0: foo b.');
830830

831831
$routes = new RouteCollection();
832832
$routes->add('a', new Route('/foo'));
@@ -841,7 +841,7 @@ public function testDeprecatedAliasWithCustomMessage()
841841
*/
842842
public function testTargettingADeprecatedAliasShouldTriggerDeprecation()
843843
{
844-
$this->expectDeprecation('Since foo/bar 1.0.0: foo b.');
844+
$this->expectUserDeprecationMessage('Since foo/bar 1.0.0: foo b.');
845845

846846
$routes = new RouteCollection();
847847
$routes->add('a', new Route('/foo'));

0 commit comments

Comments
 (0)