Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fixed parsing deprecated definitions without message key #40541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ?? '');
}
}

Expand Down Expand Up @@ -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'])) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down