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();