Skip to content

[PhpUnitBridge] Deprecate @expectedDeprecation annotation #36034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions UPGRADE-5.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ Notifier
* [BC BREAK] The `EmailMessage::fromNotification()` and `SmsMessage::fromNotification()`
methods' `$transport` argument was removed.

PhpUnitBridge
-------------

* Deprecated the `@expectedDeprecation` annotation, use the `ExpectDeprecationTrait::expectDeprecation()` method instead.

Routing
-------

Expand Down
5 changes: 5 additions & 0 deletions UPGRADE-6.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ Messenger
* Removed RedisExt transport. Run `composer require symfony/redis-messenger` to keep the transport in your application.
* Use of invalid options in Redis and AMQP connections now throws an error.

PhpUnitBridge
-------------

* Removed support for `@expectedDeprecation` annotations, use the `ExpectDeprecationTrait::expectDeprecation()` method instead.

Routing
-------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader;
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface;
use Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
use Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface;

Expand All @@ -27,6 +28,8 @@
*/
class DoctrineChoiceLoaderTest extends TestCase
{
use ExpectDeprecationTrait;

/**
* @var ChoiceListFactoryInterface|MockObject
*/
Expand Down Expand Up @@ -192,11 +195,10 @@ public function testLoadValuesForChoicesDoesNotLoadIfEmptyChoices()

/**
* @group legacy
*
* @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.
*/
public function testLoadValuesForChoicesDoesNotLoadIfSingleIntId()
{
$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.');
$loader = new DoctrineChoiceLoader(
$this->om,
$this->class,
Expand Down Expand Up @@ -295,11 +297,10 @@ public function testLoadChoicesForValuesDoesNotLoadIfEmptyValues()

/**
* @group legacy
*
* @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.
*/
public function legacyTestLoadChoicesForValuesLoadsOnlyChoicesIfValueUseIdReader()
{
$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.');
$loader = new DoctrineChoiceLoader(
$this->om,
$this->class,
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bridge/PhpUnit/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CHANGELOG
* ignore verbosity settings when the build fails because of deprecations
* added per-group verbosity
* added `ExpectDeprecationTrait` to be able to define an expected deprecation from inside a test
* deprecated the `@expectedDeprecation` annotation, use the `ExpectDeprecationTrait::expectDeprecation()` method instead

5.0.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ public function startTest($test)
if (isset($annotations['method']['expectedDeprecation'])) {
self::$expectedDeprecations = $annotations['method']['expectedDeprecation'];
self::$previousErrorHandler = set_error_handler([self::class, 'handleError']);
@trigger_error('Since symfony/phpunit-bridge 5.1: Using "@expectedDeprecation" annotations in tests is deprecated, use the "ExpectDeprecationTrait::expectDeprecation()" method instead.', E_USER_DEPRECATED);
}

if ($this->checkNumAssertions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\DependencyInjection\Tests\Compiler;

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\Compiler\ResolveReferencesToAliasesPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -20,6 +21,8 @@

class ResolveReferencesToAliasesPassTest extends TestCase
{
use ExpectDeprecationTrait;

public function testProcess()
{
$container = new ContainerBuilder();
Expand Down Expand Up @@ -83,10 +86,10 @@ public function testResolveFactory()

/**
* @group legacy
* @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.
*/
public function testDeprecationNoticeWhenReferencedByAlias()
{
$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.');
$container = new ContainerBuilder();

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

/**
* @group legacy
* @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.
*/
public function testDeprecationNoticeWhenReferencedByDefinition()
{
$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.');
$container = new ContainerBuilder();

$container->register('foo', 'stdClass');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Argument\AbstractArgument;
Expand Down Expand Up @@ -49,6 +50,8 @@

class PhpDumperTest extends TestCase
{
use ExpectDeprecationTrait;

protected static $fixturesPath;

public static function setUpBeforeClass(): void
Expand Down Expand Up @@ -410,10 +413,10 @@ public function testAliases()

/**
* @group legacy
* @expectedDeprecation The "alias_for_foo_deprecated" service alias is deprecated. You should stop using it, as it will be removed in the future.
*/
public function testAliasesDeprecation()
{
$this->expectDeprecation('The "alias_for_foo_deprecated" service alias is deprecated. You should stop using it, as it will be removed in the future.');
$container = include self::$fixturesPath.'/containers/container_alias_deprecation.php';
$container->compile();
$dumper = new PhpDumper($container);
Expand Down Expand Up @@ -1192,10 +1195,10 @@ public function testAdawsonContainer()
* This test checks the trigger of a deprecation note and should not be removed in major releases.
*
* @group legacy
* @expectedDeprecation The "foo" service is deprecated. You should stop using it, as it will be removed in the future.
*/
public function testPrivateServiceTriggersDeprecation()
{
$this->expectDeprecation('The "foo" service is deprecated. You should stop using it, as it will be removed in the future.');
$container = new ContainerBuilder();
$container->register('foo', 'stdClass')
->setPublic(false)
Expand Down Expand Up @@ -1344,11 +1347,11 @@ public function testWither()

/**
* @group legacy
* @expectedDeprecation The "deprecated1" service alias is deprecated. You should stop using it, as it will be removed in the future.
* @expectedDeprecation The "deprecated2" service alias is deprecated. You should stop using it, as it will be removed in the future.
*/
public function testMultipleDeprecatedAliasesWorking()
{
$this->expectDeprecation('The "deprecated1" service alias is deprecated. You should stop using it, as it will be removed in the future.');
$this->expectDeprecation('The "deprecated2" service alias is deprecated. You should stop using it, as it will be removed in the future.');
$container = new ContainerBuilder();
$container->setDefinition('bar', new Definition('stdClass'))->setPublic(true);
$container->setAlias('deprecated1', 'bar')->setPublic(true)->setDeprecated('%alias_id% is deprecated');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Messenger\Bridge\Amqp\Tests\Transport;

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Messenger\Bridge\Amqp\Tests\Fixtures\DummyMessage;
use Symfony\Component\Messenger\Bridge\Amqp\Transport\AmqpFactory;
use Symfony\Component\Messenger\Bridge\Amqp\Transport\AmqpStamp;
Expand All @@ -23,6 +24,8 @@
*/
class ConnectionTest extends TestCase
{
use ExpectDeprecationTrait;

private const DEFAULT_EXCHANGE_NAME = 'messages';

public function testItCannotBeConstructedWithAWrongDsn()
Expand Down Expand Up @@ -104,37 +107,37 @@ public function testOptionsAreTakenIntoAccountAndOverwrittenByDsn()

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

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Messenger\Bridge\Redis\Tests\Transport;

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Messenger\Bridge\Redis\Transport\Connection;
use Symfony\Component\Messenger\Exception\TransportException;

Expand All @@ -20,6 +21,8 @@
*/
class ConnectionTest extends TestCase
{
use ExpectDeprecationTrait;

public static function setUpBeforeClass(): void
{
$redis = Connection::fromDsn('redis://localhost/queue');
Expand Down Expand Up @@ -109,11 +112,11 @@ public function testFromDsnWithQueryOptions()
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
namespace Symfony\Component\Security\Core\Tests\Authorization\Voter;

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Security\Core\Authentication\Token\AbstractToken;
use Symfony\Component\Security\Core\Authorization\Voter\RoleVoter;
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;

class RoleVoterTest extends TestCase
{
use ExpectDeprecationTrait;

/**
* @dataProvider getVoteTests
*/
Expand Down Expand Up @@ -46,10 +49,10 @@ public function getVoteTests()

/**
* @group legacy
* @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.
*/
public function testDeprecatedRolePreviousAdmin()
{
$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.');
$voter = new RoleVoter();

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