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