8000 [PhpUnitBridge] Add ExpectUserDeprecationMessageTrait · symfony/symfony@2485e15 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2485e15

Browse files
committed
[PhpUnitBridge] Add ExpectUserDeprecationMessageTrait
1 parent 9f2133f commit 2485e15

File tree

14 files changed

+82
-47
lines changed

14 files changed

+82
-47
lines changed

src/Symfony/Bridge/PhpUnit/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.2
5+
---
6+
7+
* Add `ExpectUserDeprecationMessageTrait` with a polyfill of PHPUnit's `expectUserDeprecationMessage()`
8+
49
6.4
510
---
611

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\PhpUnit;
13+
14+
use PHPUnit\Runner\Version;
15+
16+
if (version_compare(Version::id(), '11.0.0', '<')) {
17+
trait ExpectUserDeprecationMessageTrait
18+
{
19+
use ExpectDeprecationTrait;
20+
21+
final protected function expectUserDeprecationMessage(string $expectedUserDeprecationMessage): void
22+
{
23+
$this->expectDeprecation($expectedUserDeprecationMessage);
24+
}
25+
}
26+
} else {
27+
trait ExpectUserDeprecationMessageTrait
28+
{
29+
}
30+
}

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Bundle\TwigBundle\Tests\DependencyInjection;
1313

14-
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
14+
use Symfony\Bridge\PhpUnit\ExpectUserDeprecationMessageTrait;
1515
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\RuntimeLoaderPass;
1616
use Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension;
1717
use Symfony\Bundle\TwigBundle\Tests\DependencyInjection\AcmeBundle\AcmeBundle;
@@ -32,7 +32,7 @@
3232

3333
class TwigExtensionTest extends TestCase
3434
{
35-
use ExpectDeprecationTrait;
35+
use ExpectUserDeprecationMessageTrait;
3636

3737
public function testLoadEmptyConfiguration()
3838
{
@@ -111,7 +111,7 @@ public function testLoadCustomBaseTemplateClassConfiguration(string $format)
111111
$container = $this->createContainer();
112112
$container->registerExtension(new TwigExtension());
113113

114-
$this->expectDeprecation('Since symfony/twig-bundle 7.1: The child node "base_template_class" at path "twig" is deprecated.');
114+
$this->expectUserDeprecationMessage('Since symfony/twig-bundle 7.1: The child node "base_template_class" at path "twig" is deprecated.');
115115

116116
$this->loadFromFile($container, 'templateClass', $format);
117117
$this->compileContainer($container);

src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapConfigReaderTest.php

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

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
15+
use Symfony\Bridge\PhpUnit\ExpectUserDeprecationMessageTrait;
1616
use Symfony\Component\AssetMapper\ImportMap\ImportMapConfigReader;
1717
use Symfony\Component\AssetMapper\ImportMap\ImportMapEntries;
1818
use Symfony\Component\AssetMapper\ImportMap\ImportMapEntry;
@@ -22,7 +22,7 @@
2222

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

2727
private Filesystem $filesystem;
2828

@@ -168,7 +168,7 @@ public function testFindRootImportMapEntry()
168168
*/
169169
public function testDeprecatedMethodTriggerDeprecation()
170170
{
171-
$this->expectDeprecation('Since symfony/asset-mapper 7.1: The method "Symfony\Component\AssetMapper\ImportMap\ImportMapConfigReader::splitPackageNameAndFilePath()" is deprecated and will be removed in 8.0. Use ImportMapEntry::splitPackageNameAndFilePath() instead.');
171+
$this->expectUserDeprecationMessage('Since symfony/asset-mapper 7.1: The method "Symfony\Component\AssetMapper\ImportMap\ImportMapConfigReader::splitPackageNameAndFilePath()" is deprecated and will be removed in 8.0. Use ImportMapEntry::splitPackageNameAndFilePath() instead.');
172172
ImportMapConfigReader::splitPackageNameAndFilePath('foo');
173173
}
174174
}

src/Symfony/Component/Cache/Tests/Adapter/CouchbaseBucketAdapterTest.php

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

1414
use Psr\Cache\CacheItemPoolInterface;
15-
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
15+
use Symfony\Bridge\PhpUnit\ExpectUserDeprecationMessageTrait;
1616
use Symfony\Component\Cache\Adapter\AbstractAdapter;
1717
use Symfony\Component\Cache\Adapter\CouchbaseBucketAdapter;
1818

@@ -26,7 +26,7 @@
2626
*/
2727
class CouchbaseBucketAdapterTest extends AdapterTestCase
2828
{
29-
use ExpectDeprecationTrait;
29+
use ExpectUserDeprecationMessageTrait;
3030

3131
protected $skippedTests = [
3232
'testClearPrefix' => 'Couchbase cannot clear by prefix',
@@ -36,7 +36,7 @@ class CouchbaseBucketAdapterTest extends AdapterTestCase
3636

3737
protected function setUp(): void
3838
{
39-
$this->expectDeprecation('Since symfony/cache 7.1: The "Symfony\Component\Cache\Adapter\CouchbaseBucketAdapter" class is deprecated, use "Symfony\Component\Cache\Adapter\CouchbaseCollectionAdapter" instead.');
39+
$this->expectUserDeprecationMessage('Since symfony/cache 7.1: The "Symfony\Component\Cache\Adapter\CouchbaseBucketAdapter" class is deprecated, use "Symfony\Component\Cache\Adapter\CouchbaseCollectionAdapter" instead.');
4040

4141
$this->client = AbstractAdapter::createConnection('couchbase://'.getenv('COUCHBASE_HOST').'/cache',
4242
['username' => getenv('COUCHBASE_USER'), 'password' => getenv('COUCHBASE_PASS')]

src/Symfony/Component/DependencyInjection/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');

src/Symfony/Component/DependencyInjection/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

src/Symfony/Component/DependencyInjection/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

src/Symfony/Component/DependencyInjection/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
}

src/Symfony/Component/DependencyInjection/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
}

src/Symfony/Component/Form/Tests/Extension/Core/Type/UrlTypeTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111

1212
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
1313

14-
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
14+
use Symfony\Bridge\PhpUnit\ExpectUserDeprecationMessageTrait;
1515
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
1616

1717
class UrlTypeTest extends TextTypeTest
1818
{
19-
use ExpectDeprecationTrait;
19+
use ExpectUserDeprecationMessageTrait;
2020

2121
public const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\UrlType';
2222

@@ -25,7 +25,7 @@ class UrlTypeTest extends TextTypeTest
2525
*/
2626
public function testSubmitAddsDefaultProtocolIfNoneIsIncluded()
2727
{
28-
$this->expectDeprecation('Since symfony/form 7.1: Not configuring the "default_protocol" option when using the UrlType is deprecated. It will default to "null" in 8.0.');
28+
$this->expectUserDeprecationMessage('Since symfony/form 7.1: Not configuring the "default_protocol" option when using the UrlType is deprecated. It will default to "null" in 8.0.');
2929
$form = $this->factory->create(static::TESTED_TYPE, 'name');
3030

3131
$form->submit('www.domain.com');

src/Symfony/Component/Routing/Tests/Generator/Dumper/CompiledUrlGeneratorDumperTest.php

Lines changed: 5 additions & 5 deletions
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')

0 commit comments

Comments
 (0)
0