90852c359e51458c3177d0e069a057357b681f8d
[yaffs-website] / vendor / symfony / dependency-injection / Tests / Extension / ExtensionTest.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\DependencyInjection\Tests\Extension;
13
14 use PHPUnit\Framework\TestCase;
15
16 class ExtensionTest extends TestCase
17 {
18     /**
19      * @dataProvider getResolvedEnabledFixtures
20      */
21     public function testIsConfigEnabledReturnsTheResolvedValue($enabled)
22     {
23         $pb = $this->getMockBuilder('Symfony\Component\DependencyInjection\ParameterBag\ParameterBag')
24             ->setMethods(array('resolveValue'))
25             ->getMock()
26         ;
27
28         $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')
29             ->setMethods(array('getParameterBag'))
30             ->getMock()
31         ;
32
33         $pb->expects($this->once())
34             ->method('resolveValue')
35             ->with($this->equalTo($enabled))
36             ->will($this->returnValue($enabled))
37         ;
38
39         $container->expects($this->once())
40             ->method('getParameterBag')
41             ->will($this->returnValue($pb))
42         ;
43
44         $extension = $this->getMockBuilder('Symfony\Component\DependencyInjection\Extension\Extension')
45             ->setMethods(array())
46             ->getMockForAbstractClass()
47         ;
48
49         $r = new \ReflectionMethod('Symfony\Component\DependencyInjection\Extension\Extension', 'isConfigEnabled');
50         $r->setAccessible(true);
51
52         $r->invoke($extension, $container, array('enabled' => $enabled));
53     }
54
55     public function getResolvedEnabledFixtures()
56     {
57         return array(
58             array(true),
59             array(false),
60         );
61     }
62
63     /**
64      * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
65      * @expectedExceptionMessage The config array has no 'enabled' key.
66      */
67     public function testIsConfigEnabledOnNonEnableableConfig()
68     {
69         $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')
70             ->getMock()
71         ;
72
73         $extension = $this->getMockBuilder('Symfony\Component\DependencyInjection\Extension\Extension')
74             ->setMethods(array())
75             ->getMockForAbstractClass()
76         ;
77
78         $r = new \ReflectionMethod('Symfony\Component\DependencyInjection\Extension\Extension', 'isConfigEnabled');
79         $r->setAccessible(true);
80
81         $r->invoke($extension, $container, array());
82     }
83 }