4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpKernel\Tests\Bundle;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\DependencyInjection\ContainerBuilder;
16 use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionNotValidBundle\ExtensionNotValidBundle;
17 use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\ExtensionPresentBundle;
18 use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionAbsentBundle\ExtensionAbsentBundle;
19 use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand;
21 class BundleTest extends TestCase
23 public function testGetContainerExtension()
25 $bundle = new ExtensionPresentBundle();
27 $this->assertInstanceOf(
28 'Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\DependencyInjection\ExtensionPresentExtension',
29 $bundle->getContainerExtension()
33 public function testRegisterCommands()
35 $cmd = new FooCommand();
36 $app = $this->getMockBuilder('Symfony\Component\Console\Application')->getMock();
37 $app->expects($this->once())->method('add')->with($this->equalTo($cmd));
39 $bundle = new ExtensionPresentBundle();
40 $bundle->registerCommands($app);
42 $bundle2 = new ExtensionAbsentBundle();
44 $this->assertNull($bundle2->registerCommands($app));
48 * @expectedException \LogicException
49 * @expectedExceptionMessage must implement Symfony\Component\DependencyInjection\Extension\ExtensionInterface
51 public function testGetContainerExtensionWithInvalidClass()
53 $bundle = new ExtensionNotValidBundle();
54 $bundle->getContainerExtension();
57 public function testHttpKernelRegisterCommandsIgnoresCommandsThatAreRegisteredAsServices()
59 $container = new ContainerBuilder();
60 $container->register('console.command.symfony_component_httpkernel_tests_fixtures_extensionpresentbundle_command_foocommand', 'Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand');
62 $application = $this->getMockBuilder('Symfony\Component\Console\Application')->getMock();
63 // add() is never called when the found command classes are already registered as services
64 $application->expects($this->never())->method('add');
66 $bundle = new ExtensionPresentBundle();
67 $bundle->setContainer($container);
68 $bundle->registerCommands($application);