Security update for Core, with self-updated composer
[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\Bundle\Bundle;
17 use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionNotValidBundle\ExtensionNotValidBundle;
18 use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\ExtensionPresentBundle;
19 use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionAbsentBundle\ExtensionAbsentBundle;
20 use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand;
21
22 class BundleTest extends TestCase
23 {
24     public function testGetContainerExtension()
25     {
26         $bundle = new ExtensionPresentBundle();
27
28         $this->assertInstanceOf(
29             'Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\DependencyInjection\ExtensionPresentExtension',
30             $bundle->getContainerExtension()
31         );
32     }
33
34     public function testRegisterCommands()
35     {
36         $cmd = new FooCommand();
37         $app = $this->getMockBuilder('Symfony\Component\Console\Application')->getMock();
38         $app->expects($this->once())->method('add')->with($this->equalTo($cmd));
39
40         $bundle = new ExtensionPresentBundle();
41         $bundle->registerCommands($app);
42
43         $bundle2 = new ExtensionAbsentBundle();
44
45         $this->assertNull($bundle2->registerCommands($app));
46     }
47
48     /**
49      * @expectedException \LogicException
50      * @expectedExceptionMessage must implement Symfony\Component\DependencyInjection\Extension\ExtensionInterface
51      */
52     public function testGetContainerExtensionWithInvalidClass()
53     {
54         $bundle = new ExtensionNotValidBundle();
55         $bundle->getContainerExtension();
56     }
57
58     public function testHttpKernelRegisterCommandsIgnoresCommandsThatAreRegisteredAsServices()
59     {
60         $container = new ContainerBuilder();
61         $container->register('console.command.symfony_component_httpkernel_tests_fixtures_extensionpresentbundle_command_foocommand', 'Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand');
62
63         $application = $this->getMockBuilder('Symfony\Component\Console\Application')->getMock();
64         // add() is never called when the found command classes are already registered as services
65         $application->expects($this->never())->method('add');
66
67         $bundle = new ExtensionPresentBundle();
68         $bundle->setContainer($container);
69         $bundle->registerCommands($application);
70     }
71
72     public function testBundleNameIsGuessedFromClass()
73     {
74         $bundle = new GuessedNameBundle();
75
76         $this->assertSame('Symfony\Component\HttpKernel\Tests\Bundle', $bundle->getNamespace());
77         $this->assertSame('GuessedNameBundle', $bundle->getName());
78     }
79
80     public function testBundleNameCanBeExplicitlyProvided()
81     {
82         $bundle = new NamedBundle();
83
84         $this->assertSame('ExplicitlyNamedBundle', $bundle->getName());
85         $this->assertSame('Symfony\Component\HttpKernel\Tests\Bundle', $bundle->getNamespace());
86         $this->assertSame('ExplicitlyNamedBundle', $bundle->getName());
87     }
88 }
89
90 class NamedBundle extends Bundle
91 {
92     public function __construct()
93     {
94         $this->name = 'ExplicitlyNamedBundle';
95     }
96 }
97
98 class GuessedNameBundle extends Bundle
99 {
100 }