|
19 | 19 |
|
20 | 20 | class AddConsoleCommandPassTest extends \PHPUnit_Framework_TestCase
|
21 | 21 | {
|
22 |
| - public function testProcess() |
| 22 | + /** |
| 23 | + * @dataProvider visibilityProvider |
| 24 | + */ |
| 25 | + public function testProcess($public) |
23 | 26 | {
|
24 | 27 | $container = new ContainerBuilder();
|
25 | 28 | $container->addCompilerPass(new AddConsoleCommandPass());
|
26 | 29 | $container->setParameter('my-command.class', 'Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\MyCommand');
|
27 | 30 |
|
28 | 31 | $definition = new Definition('%my-command.class%');
|
| 32 | + $definition->setPublic($public); |
29 | 33 | $definition->addTag('console.command');
|
30 | 34 | $container->setDefinition('my-command', $definition);
|
31 | 35 |
|
32 | 36 | $container->compile();
|
33 | 37 |
|
34 | 38 | $alias = 'console.command.symfony_bundle_frameworkbundle_tests_dependencyinjection_compiler_mycommand';
|
35 |
| - $this->assertTrue($container->hasAlias($alias)); |
36 |
| - $this->assertSame('my-command', (string) $container->getAlias($alias)); |
| 39 | + if ($container->hasAlias($alias)) { |
| 40 | + $this->assertSame('my-command', (string) $container->getAlias($alias)); |
| 41 | + } else { |
| 42 | + // The alias is replaced by a Definition by the ReplaceAliasByActualDefinitionPass |
| 43 | + // in case the original service is private |
| 44 | + $this->assertFalse($container->hasDefinition('my-command')); |
| 45 | + $this->assertTrue($container->hasDefinition($alias)); |
| 46 | + } |
37 | 47 |
|
38 | 48 | $this->assertTrue($container->hasParameter('console.command.ids'));
|
39 |
| - $this->assertSame(array('my-command'), $container->getParameter('console.command.ids')); |
| 49 | + $this->assertSame(array('console.command.symfony_bundle_frameworkbundle_tests_dependencyinjection_compiler_mycommand'), $container->getParameter('console.command.ids')); |
40 | 50 | }
|
41 | 51 |
|
42 |
| - /** |
43 |
| - * @expectedException \InvalidArgumentException |
44 |
| - * @expectedExceptionMessage The service "my-command" tagged "console.command" must be public. |
45 |
| - */ |
46 |
| - public function testProcessThrowAnExceptionIfTheServiceIsNotPublic() |
| 52 | + public function visibilityProvider() |
47 | 53 | {
|
48 |
| - $container = new ContainerBuilder(); |
49 |
| - $container->addCompilerPass(new AddConsoleCommandPass()); |
50 |
| - |
51 |
| - $definition = new Definition('Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\MyCommand'); |
52 |
| - $definition->addTag('console.command'); |
53 |
| - $definition->setPublic(false); |
54 |
| - $container->setDefinition('my-command', $definition); |
55 |
| - |
56 |
| - $container->compile(); |
| 54 | + return array( |
| 55 | + array(true), |
| 56 | + array(false), |
| 57 | + ); |
57 | 58 | }
|
58 | 59 |
|
59 | 60 | /**
|
|
0 commit comments