diff --git a/src/Symfony/Component/DependencyInjection/Tests/AliasTest.php b/src/Symfony/Component/DependencyInjection/Tests/AliasTest.php index 79f82c6436..b9edef0840 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/AliasTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/AliasTest.php @@ -12,10 +12,13 @@ namespace Symfony\Component\DependencyInjection\Tests; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\DependencyInjection\Alias; class AliasTest extends TestCase { + use ExpectDeprecationTrait; + public function testConstructor() { $alias = new Alias('foo'); @@ -59,10 +62,11 @@ class AliasTest extends TestCase /** * @group legacy - * @expectedDeprecation Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Alias::setDeprecated()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated. */ public function testItHasADefaultDeprecationMessage() { + $this->expectDeprecation('Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Alias::setDeprecated()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.'); + $alias = new Alias('foo', false); $alias->setDeprecated(); @@ -72,10 +76,11 @@ class AliasTest extends TestCase /** * @group legacy - * @expectedDeprecation Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Alias::setDeprecated()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated. */ public function testSetDeprecatedWithoutPackageAndVersion() { + $this->expectDeprecation('Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Alias::setDeprecated()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.'); + $def = new Alias('stdClass'); $def->setDeprecated(true, '%alias_id%'); @@ -98,11 +103,12 @@ class AliasTest extends TestCase /** * @group legacy - * @expectedDeprecation Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Alias::setDeprecated()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated. - * @expectedDeprecation Since symfony/dependency-injection 5.1: Passing a null message to un-deprecate a node is deprecated. */ public function testCanOverrideDeprecation() { + $this->expectDeprecation('Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Alias::setDeprecated()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.'); + $this->expectDeprecation('Since symfony/dependency-injection 5.1: Passing a null message to un-deprecate a node is deprecated.'); + $alias = new Alias('foo', false); $alias->setDeprecated('vendor/package', '1.1', 'The "%alias_id%" is deprecated.'); $this->assertTrue($alias->isDeprecated()); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveChildDefinitionsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveChildDefinitionsPassTest.php index 9f3b92cb54..cbf21c7925 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveChildDefinitionsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveChildDefinitionsPassTest.php @@ -12,12 +12,15 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass; use Symfony\Component\DependencyInjection\ContainerBuilder; class ResolveChildDefinitionsPassTest extends TestCase { + use ExpectDeprecationTrait; + public function testProcess() { $container = new ContainerBuilder(); @@ -310,11 +313,12 @@ class ResolveChildDefinitionsPassTest extends TestCase /** * @group legacy - * @expectedDeprecation Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Definition::setDeprecated()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated. - * @expectedDeprecation Since symfony/dependency-injection 5.1: Passing a null message to un-deprecate a node is deprecated. */ public function testDecoratedServiceCanOverwriteDeprecatedParentStatus() { + $this->expectDeprecation('Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Definition::setDeprecated()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.'); + $this->expectDeprecation('Since symfony/dependency-injection 5.1: Passing a null message to un-deprecate a node is deprecated.'); + $container = new ContainerBuilder(); $container->register('deprecated_parent') ->setDeprecated(true) diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php index 174fa81d10..93db5b694d 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php @@ -17,6 +17,7 @@ require_once __DIR__.'/Fixtures/includes/ProjectExtension.php'; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface as PsrContainerInterface; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\Config\Resource\ComposerResource; use Symfony\Component\Config\Resource\DirectoryResource; use Symfony\Component\Config\Resource\FileResource; @@ -50,6 +51,8 @@ use Symfony\Component\ExpressionLanguage\Expression; class ContainerBuilderTest extends TestCase { + use ExpectDeprecationTrait; + public function testDefaultRegisteredDefinitions() { $builder = new ContainerBuilder(); @@ -94,10 +97,11 @@ class ContainerBuilderTest extends TestCase /** * @group legacy - * @expectedDeprecation The "deprecated_foo" service is deprecated. You should stop using it, as it will be removed in the future. */ public function testCreateDeprecatedService() { + $this->expectDeprecation('The "deprecated_foo" service is deprecated. You should stop using it, as it will be removed in the future.'); + $definition = new Definition('stdClass'); $definition->setDeprecated(true); @@ -293,10 +297,11 @@ class ContainerBuilderTest extends TestCase /** * @group legacy - * @expectedDeprecation The "foobar" service alias is deprecated. You should stop using it, as it will be removed in the future. */ public function testDeprecatedAlias() { + $this->expectDeprecation('The "foobar" service alias is deprecated. You should stop using it, as it will be removed in the future.'); + $builder = new ContainerBuilder(); $builder->register('foo', 'stdClass'); diff --git a/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php b/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php index ba0ec103bb..0171aa6675 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php @@ -12,12 +12,15 @@ namespace Symfony\Component\DependencyInjection\Tests; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; class DefinitionTest extends TestCase { + use ExpectDeprecationTrait; + public function testConstructor() { $def = new Definition('stdClass'); @@ -185,10 +188,11 @@ class DefinitionTest extends TestCase /** * @group legacy - * @expectedDeprecation Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Definition::setDeprecated()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated. */ public function testSetDeprecatedWithoutPackageAndVersion() { + $this->expectDeprecation('Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Definition::setDeprecated()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.'); + $def = new Definition('stdClass'); $def->setDeprecated(true, '%service_id%'); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/PhpFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/PhpFileLoaderTest.php index aa73547df2..67524ff0df 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/PhpFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/PhpFileLoaderTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Loader; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Dumper\PhpDumper; @@ -20,6 +21,8 @@ use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; class PhpFileLoaderTest extends TestCase { + use ExpectDeprecationTrait; + public function testSupports() { $loader = new PhpFileLoader(new ContainerBuilder(), new FileLocator()); @@ -103,10 +106,11 @@ class PhpFileLoaderTest extends TestCase /** * @group legacy - * @expectedDeprecation Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Loader\Configurator\Traits\DeprecateTrait::deprecate()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated. */ public function testDeprecatedWithoutPackageAndVersion() { + $this->expectDeprecation('Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Loader\Configurator\Traits\DeprecateTrait::deprecate()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.'); + $fixtures = realpath(__DIR__.'/../Fixtures'); $loader = new PhpFileLoader($container = new ContainerBuilder(), new FileLocator()); $loader->load($fixtures.'/config/deprecated_without_package_version.php'); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php index c2835ed6a3..58003b12b3 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Loader; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\Loader\LoaderResolver; use Symfony\Component\Config\Resource\FileResource; @@ -39,6 +40,8 @@ use Symfony\Component\ExpressionLanguage\Expression; class XmlFileLoaderTest extends TestCase { + use ExpectDeprecationTrait; + protected static $fixturesPath; public static function setUpBeforeClass(): void @@ -403,10 +406,11 @@ class XmlFileLoaderTest extends TestCase /** * @group legacy - * @expectedDeprecation Since symfony/dependency-injection 5.1: Not setting the attribute "package" of the node "deprecated" is deprecated. */ public function testDeprecatedWithoutPackageAndVersion() { + $this->expectDeprecation('Since symfony/dependency-injection 5.1: Not setting the attribute "package" of the node "deprecated" is deprecated.'); + $container = new ContainerBuilder(); $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')); $loader->load('services_deprecated_without_package_and_version.xml'); @@ -435,10 +439,11 @@ class XmlFileLoaderTest extends TestCase /** * @group legacy - * @expectedDeprecation Since symfony/dependency-injection 5.1: Not setting the attribute "package" of the node "deprecated" is deprecated. */ public function testDeprecatedAliaseWithoutPackageAndVersion() { + $this->expectDeprecation('Since symfony/dependency-injection 5.1: Not setting the attribute "package" of the node "deprecated" is deprecated.'); + $container = new ContainerBuilder(); $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')); $loader->load('deprecated_alias_definitions_without_package_and_version.xml'); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php index 5611684fd4..3d90fd4c8f 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Loader; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\Loader\LoaderResolver; use Symfony\Component\Config\Resource\FileResource; @@ -38,6 +39,8 @@ use Symfony\Component\ExpressionLanguage\Expression; class YamlFileLoaderTest extends TestCase { + use ExpectDeprecationTrait; + protected static $fixturesPath; public static function setUpBeforeClass(): void @@ -232,11 +235,12 @@ class YamlFileLoaderTest extends TestCase /** * @group legacy - * @expectedDeprecation Since symfony/dependency-injection 5.1: Not setting the attribute "package" of the "deprecated" option is deprecated. - * @expectedDeprecation Since symfony/dependency-injection 5.1: Not setting the attribute "version" of the "deprecated" option is deprecated. */ public function testDeprecatedAliasesWithoutPackageAndVersion() { + $this->expectDeprecation('Since symfony/dependency-injection 5.1: Not setting the attribute "package" of the "deprecated" option is deprecated.'); + $this->expectDeprecation('Since symfony/dependency-injection 5.1: Not setting the attribute "version" of the "deprecated" option is deprecated.'); + $container = new ContainerBuilder(); $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')); $loader->load('deprecated_alias_definitions_without_package_and_version.yml'); diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php index b087206dba..7bbaf4efb6 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Form\Tests\Extension\Core\Type; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\Form\ChoiceList\Loader\CallbackChoiceLoader; use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView; use Symfony\Component\Form\ChoiceList\View\ChoiceView; @@ -19,6 +20,8 @@ use Symfony\Component\Form\Tests\Fixtures\ChoiceList\DeprecatedChoiceListFactory class ChoiceTypeTest extends BaseTypeTest { + use ExpectDeprecationTrait; + const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\ChoiceType'; private $choices = [ @@ -2146,13 +2149,13 @@ class ChoiceTypeTest extends BaseTypeTest /** * @group legacy - * - * @expectedDeprecation The "Symfony\Component\Form\Tests\Fixtures\ChoiceList\DeprecatedChoiceListFactory::createListFromChoices()" method will require a new "callable|null $filter" argument in the next major version of its interface "Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface", not defining it is deprecated. - * @expectedDeprecation The "Symfony\Component\Form\Tests\Fixtures\ChoiceList\DeprecatedChoiceListFactory::createListFromLoader()" method will require a new "callable|null $filter" argument in the next major version of its interface "Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface", not defining it is deprecated. - * @expectedDeprecation Since symfony/form 5.1: Not defining a third parameter "callable|null $filter" in "Symfony\Component\Form\Tests\Fixtures\ChoiceList\DeprecatedChoiceListFactory::createListFromChoices()" is deprecated. */ public function testUsingDeprecatedChoiceListFactory() { + $this->expectDeprecation('The "Symfony\Component\Form\Tests\Fixtures\ChoiceList\DeprecatedChoiceListFactory::createListFromChoices()" method will require a new "callable|null $filter" argument in the next major version of its interface "Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface", not defining it is deprecated.'); + $this->expectDeprecation('The "Symfony\Component\Form\Tests\Fixtures\ChoiceList\DeprecatedChoiceListFactory::createListFromLoader()" method will require a new "callable|null $filter" argument in the next major version of its interface "Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface", not defining it is deprecated.'); + $this->expectDeprecation('Since symfony/form 5.1: Not defining a third parameter "callable|null $filter" in "Symfony\Component\Form\Tests\Fixtures\ChoiceList\DeprecatedChoiceListFactory::createListFromChoices()" is deprecated.'); + new ChoiceType(new DeprecatedChoiceListFactory()); } } diff --git a/src/Symfony/Component/HttpKernel/Tests/Controller/ContainerControllerResolverTest.php b/src/Symfony/Component/HttpKernel/Tests/Controller/ContainerControllerResolverTest.php index 85dd5fb671..d394c3bce4 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Controller/ContainerControllerResolverTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Controller/ContainerControllerResolverTest.php @@ -13,18 +13,22 @@ namespace Symfony\Component\HttpKernel\Tests\Controller; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Controller\ContainerControllerResolver; class ContainerControllerResolverTest extends ControllerResolverTest { + use ExpectDeprecationTrait; + /** * @group legacy - * @expectedDeprecation Since symfony/http-kernel 5.1: Referencing controllers with a single colon is deprecated. Use "foo::action" instead. */ public function testGetControllerServiceWithSingleColon() { + $this->expectDeprecation('Since symfony/http-kernel 5.1: Referencing controllers with a single colon is deprecated. Use "foo::action" instead.'); + $service = new ControllerTestService('foo'); $container = $this->createMockContainer(); diff --git a/src/Symfony/Component/Yaml/Tests/InlineTest.php b/src/Symfony/Component/Yaml/Tests/InlineTest.php index 8213744ce3..bbae6cf3ff 100644 --- a/src/Symfony/Component/Yaml/Tests/InlineTest.php +++ b/src/Symfony/Component/Yaml/Tests/InlineTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Yaml\Tests; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\Yaml\Exception\ParseException; use Symfony\Component\Yaml\Inline; use Symfony\Component\Yaml\Tag\TaggedValue; @@ -19,6 +20,8 @@ use Symfony\Component\Yaml\Yaml; class InlineTest extends TestCase { + use ExpectDeprecationTrait; + protected function setUp(): void { Inline::initialize(0, 0); @@ -742,11 +745,11 @@ class InlineTest extends TestCase * @dataProvider phpObjectTagWithEmptyValueProvider * * @group legacy - * - * @expectedDeprecation Since symfony/yaml 5.1: Using the !php/object tag without a value is deprecated. */ public function testPhpObjectWithEmptyValue($expected, $value) { + $this->expectDeprecation('Since symfony/yaml 5.1: Using the !php/object tag without a value is deprecated.'); + $this->assertSame($expected, Inline::parse($value, Yaml::PARSE_OBJECT)); } @@ -766,11 +769,11 @@ class InlineTest extends TestCase * @dataProvider phpConstTagWithEmptyValueProvider * * @group legacy - * - * @expectedDeprecation Since symfony/yaml 5.1: Using the !php/const tag without a value is deprecated. */ public function testPhpConstTagWithEmptyValue($expected, $value) { + $this->expectDeprecation('Since symfony/yaml 5.1: Using the !php/const tag without a value is deprecated.'); + $this->assertSame($expected, Inline::parse($value, Yaml::PARSE_CONSTANT)); }