7bae54630c63eee0ced187c119f2c03c30a22760
[yaffs-website] / vendor / symfony / http-kernel / Tests / Bundle / BundleTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\HttpKernel\Tests\Bundle;
13
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;
20
21 class BundleTest extends TestCase
22 {
23     public function testGetContainerExtension()
24     {
25         $bundle = new ExtensionPresentBundle();
26
27         $this->assertInstanceOf(
28             'Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\DependencyInjection\ExtensionPresentExtension',
29             $bundle->getContainerExtension()
30         );
31     }
32
33     public function testRegisterCommands()
34     {
35         $cmd = new FooCommand();
36         $app = $this->getMockBuilder('Symfony\Component\Console\Application')->getMock();
37         $app->expects($this->once())->method('add')->with($this->equalTo($cmd));
38
39         $bundle = new ExtensionPresentBundle();
40         $bundle->registerCommands($app);
41
42         $bundle2 = new ExtensionAbsentBundle();
43
44         $this->assertNull($bundle2->registerCommands($app));
45     }
46
47     /**
48      * @expectedException \LogicException
49      * @expectedExceptionMessage must implement Symfony\Component\DependencyInjection\Extension\ExtensionInterface
50      */
51     public function testGetContainerExtensionWithInvalidClass()
52     {
53         $bundle = new ExtensionNotValidBundle();
54         $bundle->getContainerExtension();
55     }
56
57     public function testHttpKernelRegisterCommandsIgnoresCommandsThatAreRegisteredAsServices()
58     {
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');
61
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');
65
66         $bundle = new ExtensionPresentBundle();
67         $bundle->setContainer($container);
68         $bundle->registerCommands($application);
69     }
70 }