|
12 | 12 | namespace Symfony\Component\Console\Tests\DependencyInjection;
|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase;
|
| 15 | +use Symfony\Component\Console\Command\DefaultNameProviderInterface; |
15 | 16 | use Symfony\Component\Console\CommandLoader\ContainerCommandLoader;
|
16 | 17 | use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
|
17 | 18 | use Symfony\Component\Console\Command\Command;
|
@@ -78,6 +79,38 @@ public function testProcessRegistersLazyCommands()
|
78 | 79 | $this->assertSame(array(array('setName', array('my:command')), array('setAliases', array(array('my:alias')))), $command->getMethodCalls());
|
79 | 80 | }
|
80 | 81 |
|
| 82 | + public function testProcessFallsBackToDefaultName() |
| 83 | + { |
| 84 | + $container = new ContainerBuilder(); |
| 85 | + $container |
| 86 | + ->register('with-default-name', NamedCommand::class) |
| 87 | + ->setPublic(false) |
| 88 | + ->addTag('console.command') |
| 89 | + ; |
| 90 | + |
| 91 | + $pass = new AddConsoleCommandPass(); |
| 92 | + $pass->process($container); |
| 93 | + |
| 94 | + $commandLoader = $container->getDefinition('console.command_loader'); |
| 95 | + $commandLocator = $container->getDefinition((string) $commandLoader->getArgument(0)); |
| 96 | + |
| 97 | + $this->assertSame(ContainerCommandLoader::class, $commandLoader->getClass()); |
| 98 | + $this->assertSame(array('default' => 'with-default-name'), $commandLoader->getArgument(1)); |
| 99 | + $this->assertEquals(array(array('with-default-name' => new ServiceClosureArgument(new TypedReference('with-default-name', NamedCommand::class)))), $commandLocator->getArguments()); |
| 100 | + $this->assertSame(array('console.command.symfony_component_console_tests_dependencyinjection_namedcommand' => false), $container->getParameter('console.command.ids')); |
| 101 | + |
| 102 | + $container = new ContainerBuilder(); |
| 103 | + $container |
| 104 | + ->register('with-default-name', NamedCommand::class) |
| 105 | + ->setPublic(false) |
| 106 | + ->addTag('console.command', array('command' => 'new-name')) |
| 107 | + ; |
| 108 | + |
| 109 | + $pass->process($container); |
| 110 | + |
| 111 | + $this->assertSame(array('new-name' => 'with-default-name'), $container->getDefinition('console.command_loader')->getArgument(1)); |
| 112 | + } |
| 113 | + |
81 | 114 | public function visibilityProvider()
|
82 | 115 | {
|
83 | 116 | return array(
|
@@ -151,3 +184,11 @@ class MyCommand extends Command
|
151 | 184 | class ExtensionPresentBundle extends Bundle
|
152 | 185 | {
|
153 | 186 | }
|
| 187 | + |
| 188 | +class NamedCommand extends Command implements DefaultNameProviderInterface |
| 189 | +{ |
| 190 | + public static function getDefaultName() |
| 191 | + { |
| 192 | + return 'default'; |
| 193 | + } |
| 194 | +} |
0 commit comments