Skip to content

Commit 70591cd

Browse files
Merge branch '4.0' into 4.1
* 4.0: [HttpKernel] Fix restoring trusted proxies in tests Update UPGRADE-4.0.md CODEOWNERS: some more rules removed unneeded comments in tests removed unneeded comments in tests Change PHPDoc in ResponseHeaderBag::getCookies() to help IDEs [HttpKernel] fix registering IDE links [HttpKernel] Set first trusted proxy as REMOTE_ADDR in InlineFragmentRenderer. [Process] Consider \"executable\" suffixes first on Windows Triggering RememberMe's loginFail() when token cannot be created [Serializer] Fix serializer tries to denormalize null values on nullable properties [FrameworkBundle] Change priority of AddConsoleCommandPass to TYPE_BEFORE_REMOVING
2 parents 2d5d973 + 1cc17d0 commit 70591cd

File tree

1 file changed

+79
-4
lines changed

1 file changed

+79
-4
lines changed

Tests/DependencyInjection/AddConsoleCommandPassTest.php

Lines changed: 79 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
namespace Symfony\Component\Console\Tests\DependencyInjection;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Console\Command\Command;
1516
use Symfony\Component\Console\CommandLoader\ContainerCommandLoader;
1617
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
17-
use Symfony\Component\Console\Command\Command;
1818
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
19+
use Symfony\Component\DependencyInjection\ChildDefinition;
20+
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
1921
use Symfony\Component\DependencyInjection\ContainerBuilder;
2022
use Symfony\Component\DependencyInjection\Definition;
2123
use Symfony\Component\DependencyInjection\TypedReference;
@@ -28,7 +30,7 @@ class AddConsoleCommandPassTest extends TestCase
2830
public function testProcess($public)
2931
{
3032
$container = new ContainerBuilder();
31-
$container->addCompilerPass(new AddConsoleCommandPass());
33+
$container->addCompilerPass(new AddConsoleCommandPass(), PassConfig::TYPE_BEFORE_REMOVING);
3234
$container->setParameter('my-command.class', 'Symfony\Component\Console\Tests\DependencyInjection\MyCommand');
3335

3436
$id = 'my-command';
@@ -124,7 +126,7 @@ public function testProcessThrowAnExceptionIfTheServiceIsAbstract()
124126
{
125127
$container = new ContainerBuilder();
126128
$container->setResourceTracking(false);
127-
$container->addCompilerPass(new AddConsoleCommandPass());
129+
$container->addCompilerPass(new AddConsoleCommandPass(), PassConfig::TYPE_BEFORE_REMOVING);
128130

129131
$definition = new Definition('Symfony\Component\Console\Tests\DependencyInjection\MyCommand');
130132
$definition->addTag('console.command');
@@ -142,7 +144,7 @@ public function testProcessThrowAnExceptionIfTheServiceIsNotASubclassOfCommand()
142144
{
143145
$container = new ContainerBuilder();
144146
$container->setResourceTracking(false);
145-
$container->addCompilerPass(new AddConsoleCommandPass());
147+
$container->addCompilerPass(new AddConsoleCommandPass(), PassConfig::TYPE_BEFORE_REMOVING);
146148

147149
$definition = new Definition('SplObjectStorage');
148150
$definition->addTag('console.command');
@@ -171,6 +173,79 @@ public function testProcessPrivateServicesWithSameCommand()
171173
$this->assertTrue($container->hasAlias($aliasPrefix.'my-command1'));
172174
$this->assertTrue($container->hasAlias($aliasPrefix.'my-command2'));
173175
}
176+
177+
public function testProcessOnChildDefinitionWithClass()
178+
{
179+
$container = new ContainerBuilder();
180+
$container->addCompilerPass(new AddConsoleCommandPass(), PassConfig::TYPE_BEFORE_REMOVING);
181+
$className = 'Symfony\Component\Console\Tests\DependencyInjection\MyCommand';
182+
183+
$parentId = 'my-parent-command';
184+
$childId = 'my-child-command';
185+
186+
$parentDefinition = new Definition(/* no class */);
187+
$parentDefinition->setAbstract(true)->setPublic(false);
188+
189+
$childDefinition = new ChildDefinition($parentId);
190+
$childDefinition->addTag('console.command')->setPublic(true);
191+
$childDefinition->setClass($className);
192+
193+
$container->setDefinition($parentId, $parentDefinition);
194+
$container->setDefinition($childId, $childDefinition);
195+
196+
$container->compile();
197+
$command = $container->get($childId);
198+
199+
$this->assertInstanceOf($className, $command);
200+
}
201+
202+
public function testProcessOnChildDefinitionWithParentClass()
203+
{
204+
$container = new ContainerBuilder();
205+
$container->addCompilerPass(new AddConsoleCommandPass(), PassConfig::TYPE_BEFORE_REMOVING);
206+
$className = 'Symfony\Component\Console\Tests\DependencyInjection\MyCommand';
207+
208+
$parentId = 'my-parent-command';
209+
$childId = 'my-child-command';
210+
211+
$parentDefinition = new Definition($className);
212+
$parentDefinition->setAbstract(true)->setPublic(false);
213+
214+
$childDefinition = new ChildDefinition($parentId);
215+
$childDefinition->addTag('console.command')->setPublic(true);
216+
217+
$container->setDefinition($parentId, $parentDefinition);
218+
$container->setDefinition($childId, $childDefinition);
219+
220+
$container->compile();
221+
$command = $container->get($childId);
222+
223+
$this->assertInstanceOf($className, $command);
224+
}
225+
226+
/**
227+
* @expectedException \RuntimeException
228+
* @expectedExceptionMessage The definition for "my-child-command" has no class.
229+
*/
230+
public function testProcessOnChildDefinitionWithoutClass()
231+
{
232+
$container = new ContainerBuilder();
233+
$container->addCompilerPass(new AddConsoleCommandPass(), PassConfig::TYPE_BEFORE_REMOVING);
234+
235+
$parentId = 'my-parent-command';
236+
$childId = 'my-child-command';
237+
238+
$parentDefinition = new Definition();
239+
$parentDefinition->setAbstract(true)->setPublic(false);
240+
241+
$childDefinition = new ChildDefinition($parentId);
242+
$childDefinition->addTag('console.command')->setPublic(true);
243+
244+
$container->setDefinition($parentId, $parentDefinition);
245+
$container->setDefinition($childId, $childDefinition);
246+
247+
$container->compile();
248+
}
174249
}
175250

176251
class MyCommand extends Command

0 commit comments

Comments
 (0)