From d585b64953794a88ce7f4f9d36bbd4a0bd5386a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20W=C3=B3js?= Date: Mon, 22 Mar 2021 11:31:20 +0100 Subject: [PATCH] Fixed parsing deprecated definitions without message key --- .../Loader/YamlFileLoader.php | 4 ++-- .../deprecated_definition_without_message.yml | 12 +++++++++++ .../Tests/Loader/YamlFileLoaderTest.php | 21 +++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/deprecated_definition_without_message.yml diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index a941b2d3eb77c..4fe4839179af6 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -416,7 +416,7 @@ private function parseDefinition(string $id, $service, string $file, array $defa trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "version" of the "deprecated" option in "%s" is deprecated.', $file); } - $alias->setDeprecated($deprecation['package'] ?? '', $deprecation['version'] ?? '', $deprecation['message']); + $alias->setDeprecated($deprecation['package'] ?? '', $deprecation['version'] ?? '', $deprecation['message'] ?? ''); } } @@ -485,7 +485,7 @@ private function parseDefinition(string $id, $service, string $file, array $defa trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "version" of the "deprecated" option in "%s" is deprecated.', $file); } - $definition->setDeprecated($deprecation['package'] ?? '', $deprecation['version'] ?? '', $deprecation['message']); + $definition->setDeprecated($deprecation['package'] ?? '', $deprecation['version'] ?? '', $deprecation['message'] ?? ''); } if (isset($service['factory'])) { diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/deprecated_definition_without_message.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/deprecated_definition_without_message.yml new file mode 100644 index 0000000000000..7fe725fa608ff --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/deprecated_definition_without_message.yml @@ -0,0 +1,12 @@ +services: + service_without_deprecation_message: + class: Foo + deprecated: + package: vendor/package + version: 1.1 + + alias_without_deprecation_message: + alias: foobar + deprecated: + package: vendor/package + version: 1.1 diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php index 1a1dc9444a5f7..8591b9f12891a 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php @@ -220,6 +220,27 @@ public function testLoadShortSyntax() $this->assertSame(['$a' => 'a', 'App\Foo' => 'foo'], $services['bar_foo']->getArguments()); } + public function testLoadDeprecatedDefinitionWithoutMessageKey() + { + $container = new ContainerBuilder(); + $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')); + $loader->load('deprecated_definition_without_message.yml'); + + $this->assertTrue($container->getDefinition('service_without_deprecation_message')->isDeprecated()); + $deprecation = $container->getDefinition('service_without_deprecation_message')->getDeprecation('service_without_deprecation_message'); + $message = 'The "service_without_deprecation_message" service is deprecated. You should stop using it, as it will be removed in the future.'; + $this->assertSame($message, $deprecation['message']); + $this->assertSame('vendor/package', $deprecation['package']); + $this->assertSame('1.1', $deprecation['version']); + + $this->assertTrue($container->getAlias('alias_without_deprecation_message')->isDeprecated()); + $deprecation = $container->getAlias('alias_without_deprecation_message')->getDeprecation('alias_without_deprecation_message'); + $message = 'The "alias_without_deprecation_message" service alias is deprecated. You should stop using it, as it will be removed in the future.'; + $this->assertSame($message, $deprecation['message']); + $this->assertSame('vendor/package', $deprecation['package']); + $this->assertSame('1.1', $deprecation['version']); + } + public function testDeprecatedAliases() { $container = new ContainerBuilder();