a91934b3ef8f029ed02dfd78c3bc205f1c4ca349
[yaffs-website] / vendor / symfony / dependency-injection / Tests / Config / ContainerParametersResourceCheckerTest.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\Config;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Config\ResourceCheckerInterface;
16 use Symfony\Component\DependencyInjection\Config\ContainerParametersResource;
17 use Symfony\Component\DependencyInjection\Config\ContainerParametersResourceChecker;
18 use Symfony\Component\DependencyInjection\ContainerInterface;
19
20 class ContainerParametersResourceCheckerTest extends TestCase
21 {
22     /** @var ContainerParametersResource */
23     private $resource;
24
25     /** @var ResourceCheckerInterface */
26     private $resourceChecker;
27
28     /** @var ContainerInterface */
29     private $container;
30
31     protected function setUp()
32     {
33         $this->resource = new ContainerParametersResource(array('locales' => array('fr', 'en'), 'default_locale' => 'fr'));
34         $this->container = $this->getMockBuilder(ContainerInterface::class)->getMock();
35         $this->resourceChecker = new ContainerParametersResourceChecker($this->container);
36     }
37
38     public function testSupports()
39     {
40         $this->assertTrue($this->resourceChecker->supports($this->resource));
41     }
42
43     /**
44      * @dataProvider isFreshProvider
45      */
46     public function testIsFresh(callable $mockContainer, $expected)
47     {
48         $mockContainer($this->container);
49
50         $this->assertSame($expected, $this->resourceChecker->isFresh($this->resource, time()));
51     }
52
53     public function isFreshProvider()
54     {
55         yield 'not fresh on missing parameter' => array(function (\PHPUnit_Framework_MockObject_MockObject $container) {
56             $container->method('hasParameter')->with('locales')->willReturn(false);
57         }, false);
58
59         yield 'not fresh on different value' => array(function (\PHPUnit_Framework_MockObject_MockObject $container) {
60             $container->method('getParameter')->with('locales')->willReturn(array('nl', 'es'));
61         }, false);
62
63         yield 'fresh on every identical parameters' => array(function (\PHPUnit_Framework_MockObject_MockObject $container) {
64             $container->expects($this->exactly(2))->method('hasParameter')->willReturn(true);
65             $container->expects($this->exactly(2))->method('getParameter')
66                 ->withConsecutive(
67                     array($this->equalTo('locales')),
68                     array($this->equalTo('default_locale'))
69                 )
70                 ->will($this->returnValueMap(array(
71                     array('locales', array('fr', 'en')),
72                     array('default_locale', 'fr'),
73                 )))
74             ;
75         }, true);
76     }
77 }