Fixed parsing deprecated definitions without message key

This commit is contained in:
Adam Wójs 2021-03-22 11:31:20 +01:00
parent 9bb312dc59
commit d585b64953
3 changed files with 35 additions and 2 deletions

View File

@ -416,7 +416,7 @@ class YamlFileLoader extends FileLoader
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 @@ class YamlFileLoader extends FileLoader
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'])) {

View File

@ -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

View File

@ -220,6 +220,27 @@ class YamlFileLoaderTest extends TestCase
$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();