8000 feature #36034 [PhpUnitBridge] Deprecate @expectedDeprecation annotat… · symfony/symfony@1897e03 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1897e03

Browse files
committed
feature #36034 [PhpUnitBridge] Deprecate @expectedDeprecation annotation (hkdobrev)
This PR was squashed before being merged into the 5.1-dev branch. Discussion ---------- [PhpUnitBridge] Deprecate @expectedDeprecation annotation | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | yes<!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | N/A | License | MIT | Doc PR | N/A Addresses https://github.com/orgs/symfony/projects/1#card-32934769 as a follow-up to #35192. Deprecating `@expectedDeprecation` annotation on tests in favour of the `expectDeprecation()` method similar to other PHPUnit deprecations of annotations in favour of methods. Commits ------- 36a57cc [PhpUnitBridge] Deprecate @expectedDeprecation annotation
2 parents d5c4ba9 + 36a57cc commit 1897e03

File tree

10 files changed

+44
-16
lines changed

10 files changed

+44
-16
lines changed

UPGRADE-5.1.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ Notifier
5454
* [BC BREAK] The `EmailMessage::fromNotification()` and `SmsMessage::fromNotification()`
5555
methods' `$transport` argument was removed.
5656

57+
PhpUnitBridge
58+
-------------
59+
60+
* Deprecated the `@expectedDeprecation` annotation, use the `ExpectDeprecationTrait::expectDeprecation()` method instead.
61+
5762
Routing
5863
-------
5964

UPGRADE-6.0.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ Messenger
4343
* Removed RedisExt transport. Run `composer require symfony/redis-messenger` to keep the transport in your application.
4444
* Use of invalid options in Redis and AMQP connections now throws an error.
4545

46+
PhpUnitBridge
47+
-------------
48+
49+
* Removed support for `@expectedDeprecation` annotations, use the `ExpectDeprecationTrait::expectDeprecation()` method instead.
50+
4651
Routing
4752
-------
4853

src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/DoctrineChoiceLoaderTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader;
2020
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface;
2121
use Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader;
22+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
2223
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
2324
use Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface;
2425

@@ -27,6 +28,8 @@
2728
*/
2829
class DoctrineChoiceLoaderTest extends TestCase
2930
{
31+
use ExpectDeprecationTrait;
32+
3033
/**
3134
* @var ChoiceListFactoryInterface|MockObject
3235
*/
@@ -192,11 +195,10 @@ public function testLoadValuesForChoicesDoesNotLoadIfEmptyChoices()
192195

193196
/**
194197
* @group legacy
195-
*
196-
* @expectedDeprecation Since symfony/doctrine-bridge 5.1: Not defining explicitly the IdReader as value callback when query can be optimized is deprecated. Don't pass the IdReader to "Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader" or define the "choice_value" option instead.
197198
*/
198199
public function testLoadValuesForChoicesDoesNotLoadIfSingleIntId()
199200
{
201+
$this->expectDeprecation('Since symfony/doctrine-bridge 5.1: Not defining explicitly the IdReader as value callback when query can be optimized is deprecated. Don\'t pass the IdReader to "Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader" or define the "choice_value" option instead.');
200202
$loader = new DoctrineChoiceLoader(
201203
$this->om,
202204
$this->class,
@@ -295,11 +297,10 @@ public function testLoadChoicesForValuesDoesNotLoadIfEmptyValues()
295297

296298
/**
297299
* @group legacy
298-
*
299-
* @expectedDeprecation Not defining explicitly the IdReader as value callback when query can be optimized has been deprecated in 5.1. Don't pass the IdReader to "Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader" or define the choice_value instead.
300300
*/
301301
public function legacyTestLoadChoicesForValuesLoadsOnlyChoicesIfValueUseIdReader()
302302
{
303+
$this->expectDeprecation('Not defining explicitly the IdReader as value callback when query can be optimized has been deprecated in 5.1. Don\'t pass the IdReader to "Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader" or define the choice_value instead.');
303304
$loader = new DoctrineChoiceLoader(
304305
$this->om,
305306
$this->class,

src/Symfony/Bridge/PhpUnit/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CHANGELOG
77
* ignore verbosity settings when the build fails because of deprecations
88
* added per-group verbosity
99
* added `ExpectDeprecationTrait` to be able to define an expected deprecation from inside a test
10+
* deprecated the `@expectedDeprecation` annotation, use the `ExpectDeprecationTrait::expectDeprecation()` method instead
1011

1112
5.0.0
1213
-----

src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ public function startTest($test)
226226
if (isset($annotations['method']['expectedDeprecation'])) {
227227
self::$expectedDeprecations = $annotations['method']['expectedDeprecation'];
228228
self::$previousErrorHandler = set_error_handler([self::class, 'handleError']);
229+
@trigger_error('Since symfony/phpunit-bridge 5.1: Using "@expectedDeprecation" annotations in tests is deprecated, use the "ExpectDeprecationTrait::expectDeprecation()" method instead.', E_USER_DEPRECATED);
229230
}
230231

231232
if ($this->checkNumAssertions) {

src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveReferencesToAliasesPassTest.php

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

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1516
use Symfony\Component\DependencyInjection\Alias;
1617
use Symfony\Component\DependencyInjection\Compiler\ResolveReferencesToAliasesPass;
1718
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -20,6 +21,8 @@
2021

2122
class ResolveReferencesToAliasesPassTest extends TestCase
2223
{
24+
use ExpectDeprecationTrait;
25+
2326
public function testProcess()
2427
{
2528
$container = new ContainerBuilder();
@@ -83,10 +86,10 @@ public function testResolveFactory()
8386

8487
/**
8588
* @group legacy
86-
* @expectedDeprecation 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.
8789
*/
8890
public function testDeprecationNoticeWhenReferencedByAlias()
8991
{
92+
$this->expectDeprecation('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.');
9093
$container = new ContainerBuilder();
9194

9295
$container->register('foo', 'stdClass');
@@ -103,10 +106,10 @@ public function testDeprecationNoticeWhenReferencedByAlias()
103106

104107
/**
105108
* @group legacy
106-
* @expectedDeprecation 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.
107109
*/
108110
public function testDeprecationNoticeWhenReferencedByDefinition()
109111
{
112+
$this->expectDeprecation('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.');
110113
$container = new ContainerBuilder();
111114

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

src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php

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

1414
use PHPUnit\Framework\TestCase;
1515
use Psr\Container\ContainerInterface;
16+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1617
use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper;
1718
use Symfony\Component\Config\FileLocator;
1819
use Symfony\Component\DependencyInjection\Argument\AbstractArgument;
@@ -49,6 +50,8 @@
4950

5051
class PhpDumperTest extends TestCase
5152
{
53+
use ExpectDeprecationTrait;
54+
5255
protected static $fixturesPath;
5356

5457
public static function setUpBeforeClass(): void
@@ -410,10 +413,10 @@ public function testAliases()
410413

411414
/**
412415
* @group legacy
413-
* @expectedDeprecation The "alias_for_foo_deprecated" service alias is deprecated. You should stop using it, as it will be removed in the future.
414416
*/
415417
public function testAliasesDeprecation()
416418
{
419+
$this->expectDeprecation('The "alias_for_foo_deprecated" service alias is deprecated. You should stop using it, as it will be removed in the future.');
417420
$container = include self::$fixturesPath.'/containers/container_alias_deprecation.php';
418421
$container->compile();
419422
$dumper = new PhpDumper($container);
@@ -1192,10 +1195,10 @@ public function testAdawsonContainer()
11921195
* This test checks the trigger of a deprecation note and should not be removed in major releases.
11931196
*
11941197
* @group legacy
1195-
* @expectedDeprecation The "foo" service is deprecated. You should stop using it, as it will be removed in the future.
11961198
*/
11971199
public function testPrivateServiceTriggersDeprecation()
11981200
{
1201+
$this->expectDeprecation('The "foo" service is deprecated. You should stop using it, as it will be removed in the future.');
11991202
$container = new ContainerBuilder();
12001203
$container->register('foo', 'stdClass')
12011204
->setPublic(false)
@@ -1344,11 +1347,11 @@ public function testWither()
13441347

13451348
/**
13461349
* @group legacy
1347-
* @expectedDeprecation The "deprecated1" service alias is deprecated. You should stop using it, as it will be removed in the future.
1348-
* @expectedDeprecation The "deprecated2" service alias is deprecated. You should stop using it, as it will be removed in the future.
13491350
*/
13501351
public function testMultipleDeprecatedAliasesWorking()
13511352
{
1353+
$this->expectDeprecation('The "deprecated1" service alias is deprecated. You should stop using it, as it will be removed in the future.');
1354+
$this->expectDeprecation('The "deprecated2" service alias is deprecated. You should stop using it, as it will be removed in the future.');
13521355
$container = new ContainerBuilder();
13531356
$container->setDefinition('bar', new Definition('stdClass'))->setPublic(true);
13541357
$container->setAlias('deprecated1', 'bar')->setPublic(true)->setDeprecated('%alias_id% is deprecated');

src/Symfony/Component/Messenger/Bridge/Amqp/Tests/Transport/ConnectionTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Messenger\Bridge\Amqp\Tests\Transport;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1516
use Symfony\Component\Messenger\Bridge\Amqp\Tests\Fixtures\DummyMessage;
1617
use Symfony\Component\Messenger\Bridge\Amqp\Transport\AmqpFactory;
1718
use Symfony\Component\Messenger\Bridge\Amqp\Transport\AmqpStamp;
@@ -23,6 +24,8 @@
2324
*/
2425
class ConnectionTest extends TestCase
2526
{
27+
use ExpectDeprecationTrait;
28+
2629
private const DEFAULT_EXCHANGE_NAME = 'messages';
2730

2831
public function testItCannotBeConstructedWithAWrongDsn()
@@ -104,37 +107,37 @@ public function testOptionsAreTakenIntoAccountAndOverwrittenByDsn()
104107

105108
/**
106109
* @group legacy
107-
* @expectedDeprecation Since symfony/messenger 5.1: Invalid option(s) "foo" passed to the AMQP Messenger transport. Passing invalid options is deprecated.
108110
*/
109111
public function testDeprecationIfInvalidOptionIsPassedWithDsn()
110112
{
113+
$this->expectDeprecation('Since symfony/messenger 5.1: Invalid option(s) "foo" passed to the AMQP Messenger transport. Passing invalid options is deprecated.');
111114
Connection::fromDsn('amqp://host?foo=bar');
112115
}
113116

114117
/**
115118
* @group legacy
116-
* @expectedDeprecation Since symfony/messenger 5.1: Invalid option(s) "foo" passed to the AMQP Messenger transport. Passing invalid options is deprecated.
117119
*/
118120
public function testDeprecationIfInvalidOptionIsPassedAsArgument()
119121
{
122+
$this->expectDeprecation('Since symfony/messenger 5.1: Invalid option(s) "foo" passed to the AMQP Messenger transport. Passing invalid options is deprecated.');
120123
Connection::fromDsn('amqp://host', ['foo' => 'bar']);
121124
}
122125

123126
/**
124127
* @group legacy
125-
* @expectedDeprecation Since symfony/messenger 5.1: Invalid queue option(s) "foo" passed to the AMQP Messenger transport. Passing invalid queue options is deprecated.
126128
*/
127129
public function testDeprecationIfInvalidQueueOptionIsPassed()
128130
{
131+
$this->expectDeprecation('Since symfony/messenger 5.1: Invalid queue option(s) "foo" passed to the AMQP Messenger transport. Passing invalid queue options is deprecated.');
129132
Connection::fromDsn('amqp://host', ['queues' => ['queueName' => ['foo' => 'bar']]]);
130133
}
131134

132135
/**
133136
* @group legacy
134-
* @expectedDeprecation Since symfony/messenger 5.1: Invalid exchange option(s) "foo" passed to the AMQP Messenger transport. Passing invalid exchange options is deprecated.
135137
*/
136138
public function testDeprecationIfInvalidExchangeOptionIsPassed()
137139
{
140+
$this->expectDeprecation('Since symfony/messenger 5.1: Invalid exchange option(s) "foo" passed to the AMQP Messenger transport. Passing invalid exchange options is deprecated.');
138141
Connection::fromDsn('amqp://host', ['exchange' => ['foo' => 'bar']]);
139142
}
140143

src/Symfony/Component/Messenger/Bridge/Redis/Tests/Transport/ConnectionTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Messenger\Bridge\Redis\Tests\Transport;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1516
use Symfony\Component\Messenger\Bridge\Redis\Transport\Connection;
1617
use Symfony\Component\Messenger\Exception\TransportException;
1718

@@ -20,6 +21,8 @@
2021
*/
2122
class ConnectionTest extends TestCase
2223
{
24+
use ExpectDeprecationTrait;
25+
2326
public static function setUpBeforeClass(): void
2427
{
2528
$redis = Connection::fromDsn('redis://localhost/queue');
@@ -109,11 +112,11 @@ public function testFromDsnWithQueryOptions()
109112
}
110113

111114
/**
112-
* @expectedDeprecation Since symfony/messenger 5.1: Invalid option(s) "foo" passed to the Redis Messenger transport. Passing invalid options is deprecated.
113115
* @group legacy
114116
*/
115117
public function testDeprecationIfInvalidOptionIsPassedWithDsn()
116118
{
119+
$this->expectDeprecation('Since symfony/messenger 5.1: Invalid option(s) "foo" passed to the Redis Messenger transport. Passing invalid options is deprecated.');
117120
Connection::fromDsn('redis://localhost/queue?foo=bar');
118121
}
119122

src/Symfony/Component/Security/Core/Tests/Authorization/Voter/RoleVoterTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
namespace Symfony\Component\Security\Core\Tests\Authorization\Voter;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1516
use Symfony\Component\Security\Core\Authentication\Token\AbstractToken;
1617
use Symfony\Component\Security\Core\Authorization\Voter\RoleVoter;
1718
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
1819

1920
class RoleVoterTest extends TestCase
2021
{
22+
use ExpectDeprecationTrait;
23+
2124
/**
2225
* @dataProvider getVoteTests
2326
*/
@@ -46,10 +49,10 @@ public function getVoteTests()
4649

4750
/**
4851
* @group legacy
49-
* @expectedDeprecation Since symfony/security-core 5.1: The ROLE_PREVIOUS_ADMIN role is deprecated and will be removed in version 6.0, use the IS_IMPERSONATOR attribute instead.
5052
*/
5153
public function testDeprecatedRolePreviousAdmin()
5254
{
55+
$this->expectDeprecation('Since symfony/security-core 5.1: The ROLE_PREVIOUS_ADMIN role is deprecated and will be removed in version 6.0, use the IS_IMPERSONATOR attribute instead.');
5356
$voter = new RoleVoter();
5457

5558
$voter->vote($this->getTokenWithRoleNames(['ROLE_USER', 'ROLE_PREVIOUS_ADMIN']), null, ['ROLE_PREVIOUS_ADMIN']);

0 commit comments

Comments
 (0)
0