Fix BC break in console.command.ids parameter
This commit is contained in:
parent
80ac529742
commit
99e95c3d2d
@ -173,8 +173,9 @@ class Application extends BaseApplication
|
||||
}
|
||||
|
||||
if ($container->hasParameter('console.command.ids')) {
|
||||
$lazyCommandIds = $container->hasParameter('console.lazy_command.ids') ? $container->getParameter('console.lazy_command.ids') : array();
|
||||
foreach ($container->getParameter('console.command.ids') as $id) {
|
||||
if (false !== $id) {
|
||||
if (!isset($lazyCommandIds[$id])) {
|
||||
try {
|
||||
$this->add($container->get($id));
|
||||
} catch (\Exception $e) {
|
||||
|
@ -183,16 +183,16 @@ class ApplicationTest extends TestCase
|
||||
}
|
||||
|
||||
$container
|
||||
->expects($this->once())
|
||||
->expects($this->exactly(2))
|
||||
->method('hasParameter')
|
||||
->with($this->equalTo('console.command.ids'))
|
||||
->will($this->returnValue(true))
|
||||
->withConsecutive(array('console.command.ids'), array('console.lazy_command.ids'))
|
||||
->willReturnOnConsecutiveCalls(true, true)
|
||||
;
|
||||
$container
|
||||
->expects($this->once())
|
||||
->expects($this->exactly(2))
|
||||
->method('getParameter')
|
||||
->with($this->equalTo('console.command.ids'))
|
||||
->will($this->returnValue(array()))
|
||||
->withConsecutive(array('console.lazy_command.ids'), array('console.command.ids'))
|
||||
->willReturnOnConsecutiveCalls(array(), array())
|
||||
;
|
||||
|
||||
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
|
||||
|
@ -41,6 +41,7 @@ class AddConsoleCommandPass implements CompilerPassInterface
|
||||
$lazyCommandMap = array();
|
||||
$lazyCommandRefs = array();
|
||||
$serviceIds = array();
|
||||
$lazyServiceIds = array();
|
||||
|
||||
foreach ($commandServices as $id => $tags) {
|
||||
$definition = $container->getDefinition($id);
|
||||
@ -73,7 +74,8 @@ class AddConsoleCommandPass implements CompilerPassInterface
|
||||
continue;
|
||||
}
|
||||
|
||||
$serviceIds[$commandId] = false;
|
||||
$serviceIds[$commandId] = $id;
|
||||
$lazyServiceIds[$id] = true;
|
||||
unset($tags[0]);
|
||||
$lazyCommandMap[$commandName] = $id;
|
||||
$lazyCommandRefs[$id] = new TypedReference($id, $class);
|
||||
@ -98,5 +100,6 @@ class AddConsoleCommandPass implements CompilerPassInterface
|
||||
->setArguments(array(ServiceLocatorTagPass::register($container, $lazyCommandRefs), $lazyCommandMap));
|
||||
|
||||
$container->setParameter('console.command.ids', $serviceIds);
|
||||
$container->setParameter('console.lazy_command.ids', $lazyServiceIds);
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +73,8 @@ class AddConsoleCommandPassTest extends TestCase
|
||||
$this->assertSame(ContainerCommandLoader::class, $commandLoader->getClass());
|
||||
$this->assertSame(array('my:command' => 'my-command', 'my:alias' => 'my-command'), $commandLoader->getArgument(1));
|
||||
$this->assertEquals(array(array('my-command' => new ServiceClosureArgument(new TypedReference('my-command', MyCommand::class)))), $commandLocator->getArguments());
|
||||
$this->assertSame(array('console.command.symfony_component_console_tests_dependencyinjection_mycommand' => false), $container->getParameter('console.command.ids'));
|
||||
$this->assertSame(array('console.command.symfony_component_console_tests_dependencyinjection_mycommand' => 'my-command'), $container->getParameter('console.command.ids'));
|
||||
$this->assertSame(array('my-command' => true), $container->getParameter('console.lazy_command.ids'));
|
||||
$this->assertSame(array(array('setName', array('my:command')), array('setAliases', array(array('my:alias')))), $command->getMethodCalls());
|
||||
}
|
||||
|
||||
@ -95,7 +96,8 @@ class AddConsoleCommandPassTest extends TestCase
|
||||
$this->assertSame(ContainerCommandLoader::class, $commandLoader->getClass());
|
||||
$this->assertSame(array('default' => 'with-default-name'), $commandLoader->getArgument(1));
|
||||
$this->assertEquals(array(array('with-default-name' => new ServiceClosureArgument(new TypedReference('with-default-name', NamedCommand::class)))), $commandLocator->getArguments());
|
||||
$this->assertSame(array('console.command.symfony_component_console_tests_dependencyinjection_namedcommand' => false), $container->getParameter('console.command.ids'));
|
||||
$this->assertSame(array('console.command.symfony_component_console_tests_dependencyinjection_namedcommand' => 'with-default-name'), $container->getParameter('console.command.ids'));
|
||||
$this->assertSame(array('with-default-name' => true), $container->getParameter('console.lazy_command.ids'));
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container
|
||||
|
Reference in New Issue
Block a user