Skip to content

Commit 1e66194

Browse files
committed
Fixed parsing deprecated definitions without message key
1 parent be0c792 commit 1e66194

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

Loader/YamlFileLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ private function parseDefinition(string $id, $service, string $file, array $defa
416416
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "version" of the "deprecated" option in "%s" is deprecated.', $file);
417417
}
418418

419-
$alias->setDeprecated($deprecation['package'] ?? '', $deprecation['version'] ?? '', $deprecation['message']);
419+
$alias->setDeprecated($deprecation['package'] ?? '', $deprecation['version'] ?? '', $deprecation['message'] ?? '');
420420
}
421421
}
422422

@@ -485,7 +485,7 @@ private function parseDefinition(string $id, $service, string $file, array $defa
485485
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "version" of the "deprecated" option in "%s" is deprecated.', $file);
486486
}
487487

488-
$definition->setDeprecated($deprecation['package'] ?? '', $deprecation['version'] ?? '', $deprecation['message']);
488+
$definition->setDeprecated($deprecation['package'] ?? '', $deprecation['version'] ?? '', $deprecation['message'] ?? '');
489489
}
490490

491491
if (isset($service['factory'])) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
services:
2+
service_without_deprecation_message:
3+
class: Foo
4+
deprecated:
5+
package: vendor/package
6+
version: 1.1
7+
8+
alias_without_deprecation_message:
9+
alias: foobar
10+
deprecated:
11+
package: vendor/package
12+
version: 1.1

Tests/Loader/YamlFileLoaderTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,27 @@ public function testLoadShortSyntax()
220220
$this->assertSame(['$a' => 'a', 'App\Foo' => 'foo'], $services['bar_foo']->getArguments());
221221
}
222222

223+
public function testLoadDeprecatedDefinitionWithoutMessageKey()
224+
{
225+
$container = new ContainerBuilder();
226+
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
227+
$loader->load('deprecated_definition_without_message.yml');
228+
229+
$this->assertTrue($container->getDefinition('service_without_deprecation_message')->isDeprecated());
230+
$deprecation = $container->getDefinition('service_without_deprecation_message')->getDeprecation('service_without_deprecation_message');
231+
$message = 'The "service_without_deprecation_message" service is deprecated. You should stop using it, as it will be removed in the future.';
232+
$this->assertSame($message, $deprecation['message']);
233+
$this->assertSame('vendor/package', $deprecation['package']);
234+
$this->assertSame('1.1', $deprecation['version']);
235+
236+
$this->assertTrue($container->getAlias('alias_without_deprecation_message')->isDeprecated());
237+
$deprecation = $container->getAlias('alias_without_deprecation_message')->getDeprecation('alias_without_deprecation_message');
238+
$message = 'The "alias_without_deprecation_message" service alias is deprecated. You should stop using it, as it will be removed in the future.';
239+
$this->assertSame($message, $deprecation['message']);
240+
$this->assertSame('vendor/package', $deprecation['package']);
241+
$this->assertSame('1.1', $deprecation['version']);
242+
}
243+
223244
public function testDeprecatedAliases()
224245
{
225246
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)