Skip to content

Commit 066ca85

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 d32bbd6 + a30030e commit 066ca85

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

Tests/Compiler/ResolveReferencesToAliasesPassTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
15+
use Symfony\Bridge\PhpUnit\ExpectUserDeprecationMessageTrait;
1616
use Symfony\Component\DependencyInjection\Alias;
1717
use Symfony\Component\DependencyInjection\Compiler\ResolveReferencesToAliasesPass;
1818
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -22,7 +22,7 @@
2222

2323
class ResolveReferencesToAliasesPassTest extends TestCase
2424
{
25-
use ExpectDeprecationTrait;
25+
use ExpectUserDeprecationMessageTrait;
2626

2727
public function testProcess()
2828
{
@@ -92,7 +92,7 @@ public function testResolveFactory()
9292
*/
9393
public function testDeprecationNoticeWhenReferencedByAlias()
9494
{
95-
$this->expectDeprecation('Since foobar 1.2.3.4: The "deprecated_foo_alias" service alias is deprecated. You should stop using it, as it will be removed in the future. It is being referenced by the "alias" alias.');
95+
$this->expectUserDeprecationMessage('Since foobar 1.2.3.4: The "deprecated_foo_alias" service alias is deprecated. You should stop using it, as it will be removed in the future. It is being referenced by the "alias" alias.');
9696
$container = new ContainerBuilder();
9797

9898
$container->register('foo', 'stdClass');
@@ -114,7 +114,7 @@ public function testDeprecationNoticeWhenReferencedByAlias()
114114
*/
115115
public function testDeprecationNoticeWhenReferencedByDefinition()
116116
{
117-
$this->expectDeprecation('Since foobar 1.2.3.4: The "foo_aliased" service alias is deprecated. You should stop using it, as it will be removed in the future. It is being referenced by the "definition" service.');
117+
$this->expectUserDeprecationMessage('Since foobar 1.2.3.4: The "foo_aliased" service alias is deprecated. You should stop using it, as it will be removed in the future. It is being referenced by the "definition" service.');
118118
$container = new ContainerBuilder();
119119

120120
$container->register('foo', 'stdClass');

Tests/ContainerBuilderTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
require_once __DIR__.'/Fixtures/includes/ProjectExtension.php';
1717

1818
use PHPUnit\Framework\TestCase;
19-
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
19+
use Symfony\Bridge\PhpUnit\ExpectUserDeprecationMessageTrait;
2020
use Symfony\Component\Config\Resource\DirectoryResource;
2121
use Symfony\Component\Config\Resource\FileResource;
2222
use Symfony\Component\Config\Resource\ResourceInterface;
@@ -62,7 +62,7 @@
6262

6363
class ContainerBuilderTest extends TestCase
6464
{
65-
use ExpectDeprecationTrait;
65+
use ExpectUserDeprecationMessageTrait;
6666

6767
public function testDefaultRegisteredDefinitions()
6868
{
@@ -116,7 +116,7 @@ public function testDeprecateParameter()
116116

117117
$builder->deprecateParameter('foo', 'symfony/test', '6.3');
118118

119-
$this->expectDeprecation('Since symfony/test 6.3: The parameter "foo" is deprecated.');
119+
$this->expectUserDeprecationMessage('Since symfony/test 6.3: The parameter "foo" is deprecated.');
120120

121121
$builder->getParameter('foo');
122122
}
@@ -134,7 +134,7 @@ public function testParameterDeprecationIsTrgiggeredWhenCompiled()
134134

135135
$builder->deprecateParameter('bar', 'symfony/test', '6.3');
136136

137-
$this->expectDeprecation('Since symfony/test 6.3: The parameter "bar" is deprecated.');
137+
$this->expectUserDeprecationMessage('Since symfony/test 6.3: The parameter "bar" is deprecated.');
138138

139139
$builder->compile();
140140
}
@@ -1918,7 +1918,7 @@ public function testAutoAliasing()
19181918
*/
19191919
public function testDirectlyAccessingDeprecatedPublicService()
19201920
{
1921-
$this->expectDeprecation('Since foo/bar 3.8: Accessing the "Symfony\Component\DependencyInjection\Tests\A" service directly from the container is deprecated, use dependency injection instead.');
1921+
$this->expectUserDeprecationMessage('Since foo/bar 3.8: Accessing the "Symfony\Component\DependencyInjection\Tests\A" service directly from the container is deprecated, use dependency injection instead.');
19221922

19231923
$container = new ContainerBuilder();
19241924
$container

Tests/Dumper/PhpDumperTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Psr\Container\ContainerInterface;
16-
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
16+
use Symfony\Bridge\PhpUnit\ExpectUserDeprecationMessageTrait;
1717
use Symfony\Component\Config\FileLocator;
1818
use Symfony\Component\DependencyInjection\Argument\AbstractArgument;
1919
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
@@ -76,7 +76,7 @@
7676

7777
class PhpDumperTest extends TestCase
7878
{
79-
use ExpectDeprecationTrait;
79+
use ExpectUserDeprecationMessageTrait;
8080

8181
protected static string $fixturesPath;
8282

@@ -485,7 +485,7 @@ public function testDeprecatedParameters()
485485
{
486486
$container = include self::$fixturesPath.'/containers/container_deprecated_parameters.php';
487487

488-
$this->expectDeprecation('Since symfony/test 6.3: The parameter "foo_class" is deprecated.');
488+
$this->expectUserDeprecationMessage('Since symfony/test 6.3: The parameter "foo_class" is deprecated.');
489489
$container->compile();
490490

491491
$dumper = new PhpDumper($container);
@@ -502,7 +502,7 @@ public function testDeprecatedParametersAsFiles()
502502
{
503503
$container = include self::$fixturesPath.'/containers/container_deprecated_parameters.php';
504504

505-
$this->expectDeprecation('Since symfony/test 6.3: The parameter "foo_class" is deprecated.');
505+
$this->expectUserDeprecationMessage('Since symfony/test 6.3: The parameter "foo_class" is deprecated.');
506506
$container->compile();
507507

508508
$dumper = new PhpDumper($container);
@@ -1702,7 +1702,7 @@ public function testDumpServiceWithAbstractArgument()
17021702
*/
17031703
public function testDirectlyAccessingDeprecatedPublicService()
17041704
{
1705-
$this->expectDeprecation('Since foo/bar 3.8: Accessing the "bar" service directly from the container is deprecated, use dependency injection instead.');
1705+
$this->expectUserDeprecationMessage('Since foo/bar 3.8: Accessing the "bar" service directly from the container is deprecated, use dependency injection instead.');
17061706

17071707
$container = new ContainerBuilder();
17081708
$container

Tests/ParameterBag/FrozenParameterBagTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
namespace Symfony\Component\DependencyInjection\Tests\ParameterBag;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
15+
use Symfony\Bridge\PhpUnit\ExpectUserDeprecationMessageTrait;
1616
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
1717

1818
class FrozenParameterBagTest extends TestCase
1919
{
20-
use ExpectDeprecationTrait;
20+
use ExpectUserDeprecationMessageTrait;
2121

2222
public function testConstructor()
2323
{
@@ -76,7 +76,7 @@ public function testGetDeprecated()
7676
['foo' => ['symfony/test', '6.3', 'The parameter "%s" is deprecated.', 'foo']]
7777
);
7878

79-
$this->expectDeprecation('Since symfony/test 6.3: The parameter "foo" is deprecated.');
79+
$this->expectUserDeprecationMessage('Since symfony/test 6.3: The parameter "foo" is deprecated.');
8080

8181
$bag->get('foo');
8282
}

Tests/ParameterBag/ParameterBagTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Component\DependencyInjection\Tests\ParameterBag;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
15+
use Symfony\Bridge\PhpUnit\ExpectUserDeprecationMessageTrait;
1616
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1717
use Symfony\Component\DependencyInjection\Exception\ParameterCircularReferenceException;
1818
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
@@ -21,7 +21,7 @@
2121

2222
class ParameterBagTest extends TestCase
2323
{
24-
use ExpectDeprecationTrait;
24+
use ExpectUserDeprecationMessageTrait;
2525

2626
public function testConstructor()
2727
{
@@ -149,7 +149,7 @@ public function testDeprecate()
149149

150150
$bag->deprecate('foo', 'symfony/test', '6.3');
151151

152-
$this->expectDeprecation('Since symfony/test 6.3: The parameter "foo" is deprecated.');
152+
$this->expectUserDeprecationMessage('Since symfony/test 6.3: The parameter "foo" is deprecated.');
153153

154154
$bag->get('foo');
155155
}
@@ -165,7 +165,7 @@ public function testDeprecateWithMessage()
165165

166166
$bag->deprecate('foo', 'symfony/test', '6.3', 'The parameter "%s" is deprecated, use "new_foo" instead.');
167167

168-
$this->expectDeprecation('Since symfony/test 6.3: The parameter "foo" is deprecated, use "new_foo" instead.');
168+
$this->expectUserDeprecationMessage('Since symfony/test 6.3: The parameter "foo" is deprecated, use "new_foo" instead.');
169169

170170
$bag->get('foo');
171171
}
@@ -181,7 +181,7 @@ public function testDeprecationIsTriggeredWhenResolved()
181181

182182
$bag->deprecate('bar', 'symfony/test', '6.3');
183183

184-
$this->expectDeprecation('Since symfony/test 6.3: The parameter "bar" is deprecated.');
184+
$this->expectUserDeprecationMessage('Since symfony/test 6.3: The parameter "bar" is deprecated.');
185185

186186
$bag->resolve();
187187
}

0 commit comments

Comments
 (0)