Pull merge.
[yaffs-website] / vendor / symfony / http-kernel / Tests / Config / EnvParametersResourceTest.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\Config;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\HttpKernel\Config\EnvParametersResource;
16
17 /**
18  * @group legacy
19  */
20 class EnvParametersResourceTest extends TestCase
21 {
22     protected $prefix = '__DUMMY_';
23     protected $initialEnv;
24     protected $resource;
25
26     protected function setUp()
27     {
28         $this->initialEnv = array(
29             $this->prefix.'1' => 'foo',
30             $this->prefix.'2' => 'bar',
31         );
32
33         foreach ($this->initialEnv as $key => $value) {
34             $_SERVER[$key] = $value;
35         }
36
37         $this->resource = new EnvParametersResource($this->prefix);
38     }
39
40     protected function tearDown()
41     {
42         foreach ($_SERVER as $key => $value) {
43             if (0 === strpos($key, $this->prefix)) {
44                 unset($_SERVER[$key]);
45             }
46         }
47     }
48
49     public function testGetResource()
50     {
51         $this->assertSame(
52             array('prefix' => $this->prefix, 'variables' => $this->initialEnv),
53             $this->resource->getResource(),
54             '->getResource() returns the resource'
55         );
56     }
57
58     public function testToString()
59     {
60         $this->assertSame(
61             serialize(array('prefix' => $this->prefix, 'variables' => $this->initialEnv)),
62             (string) $this->resource
63         );
64     }
65
66     public function testIsFreshNotChanged()
67     {
68         $this->assertTrue(
69             $this->resource->isFresh(time()),
70             '->isFresh() returns true if the variables have not changed'
71         );
72     }
73
74     public function testIsFreshValueChanged()
75     {
76         reset($this->initialEnv);
77         $_SERVER[key($this->initialEnv)] = 'baz';
78
79         $this->assertFalse(
80             $this->resource->isFresh(time()),
81             '->isFresh() returns false if a variable has been changed'
82         );
83     }
84
85     public function testIsFreshValueRemoved()
86     {
87         reset($this->initialEnv);
88         unset($_SERVER[key($this->initialEnv)]);
89
90         $this->assertFalse(
91             $this->resource->isFresh(time()),
92             '->isFresh() returns false if a variable has been removed'
93         );
94     }
95
96     public function testIsFreshValueAdded()
97     {
98         $_SERVER[$this->prefix.'3'] = 'foo';
99
100         $this->assertFalse(
101             $this->resource->isFresh(time()),
102             '->isFresh() returns false if a variable has been added'
103         );
104     }
105
106     public function testSerializeUnserialize()
107     {
108         $this->assertEquals($this->resource, unserialize(serialize($this->resource)));
109     }
110 }