3408d7acd6c0d38f1301eeb6d310c9db86be40a0
[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\ExtensionAbsentBundle\ExtensionAbsentBundle;
18 use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionNotValidBundle\ExtensionNotValidBundle;
19 use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand;
20 use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\ExtensionPresentBundle;
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     /**
35      * @group legacy
36      * @expectedDeprecation Auto-registration of the command "Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand" is deprecated since Symfony 3.4 and won't be supported in 4.0. Use PSR-4 based service discovery instead.
37      */
38     public function testRegisterCommands()
39     {
40         $cmd = new FooCommand();
41         $app = $this->getMockBuilder('Symfony\Component\Console\Application')->getMock();
42         $app->expects($this->once())->method('add')->with($this->equalTo($cmd));
43
44         $bundle = new ExtensionPresentBundle();
45         $bundle->registerCommands($app);
46
47         $bundle2 = new ExtensionAbsentBundle();
48
49         $this->assertNull($bundle2->registerCommands($app));
50     }
51
52     /**
53      * @expectedException \LogicException
54      * @expectedExceptionMessage must implement Symfony\Component\DependencyInjection\Extension\ExtensionInterface
55      */
56     public function testGetContainerExtensionWithInvalidClass()
57     {
58         $bundle = new ExtensionNotValidBundle();
59         $bundle->getContainerExtension();
60     }
61
62     public function testHttpKernelRegisterCommandsIgnoresCommandsThatAreRegisteredAsServices()
63     {
64         $container = new ContainerBuilder();
65         $container->register('console.command.symfony_component_httpkernel_tests_fixtures_extensionpresentbundle_command_foocommand', 'Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand');
66
67         $application = $this->getMockBuilder('Symfony\Component\Console\Application')->getMock();
68         // add() is never called when the found command classes are already registered as services
69         $application->expects($this->never())->method('add');
70
71         $bundle = new ExtensionPresentBundle();
72         $bundle->setContainer($container);
73         $bundle->registerCommands($application);
74     }
75
76     public function testBundleNameIsGuessedFromClass()
77     {
78         $bundle = new GuessedNameBundle();
79
80         $this->assertSame('Symfony\Component\HttpKernel\Tests\Bundle', $bundle->getNamespace());
81         $this->assertSame('GuessedNameBundle', $bundle->getName());
82     }
83
84     public function testBundleNameCanBeExplicitlyProvided()
85     {
86         $bundle = new NamedBundle();
87
88         $this->assertSame('ExplicitlyNamedBundle', $bundle->getName());
89         $this->assertSame('Symfony\Component\HttpKernel\Tests\Bundle', $bundle->getNamespace());
90         $this->assertSame('ExplicitlyNamedBundle', $bundle->getName());
91     }
92 }
93
94 class NamedBundle extends Bundle
95 {
96     public function __construct()
97     {
98         $this->name = 'ExplicitlyNamedBundle';
99     }
100 }
101
102 class GuessedNameBundle extends Bundle
103 {
104 }