4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpKernel\Tests\Config;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\HttpKernel\Config\EnvParametersResource;
20 class EnvParametersResourceTest extends TestCase
22 protected $prefix = '__DUMMY_';
23 protected $initialEnv;
26 protected function setUp()
28 $this->initialEnv = array(
29 $this->prefix.'1' => 'foo',
30 $this->prefix.'2' => 'bar',
33 foreach ($this->initialEnv as $key => $value) {
34 $_SERVER[$key] = $value;
37 $this->resource = new EnvParametersResource($this->prefix);
40 protected function tearDown()
42 foreach ($_SERVER as $key => $value) {
43 if (0 === strpos($key, $this->prefix)) {
44 unset($_SERVER[$key]);
49 public function testGetResource()
52 array('prefix' => $this->prefix, 'variables' => $this->initialEnv),
53 $this->resource->getResource(),
54 '->getResource() returns the resource'
58 public function testToString()
61 serialize(array('prefix' => $this->prefix, 'variables' => $this->initialEnv)),
62 (string) $this->resource
66 public function testIsFreshNotChanged()
69 $this->resource->isFresh(time()),
70 '->isFresh() returns true if the variables have not changed'
74 public function testIsFreshValueChanged()
76 reset($this->initialEnv);
77 $_SERVER[key($this->initialEnv)] = 'baz';
80 $this->resource->isFresh(time()),
81 '->isFresh() returns false if a variable has been changed'
85 public function testIsFreshValueRemoved()
87 reset($this->initialEnv);
88 unset($_SERVER[key($this->initialEnv)]);
91 $this->resource->isFresh(time()),
92 '->isFresh() returns false if a variable has been removed'
96 public function testIsFreshValueAdded()
98 $_SERVER[$this->prefix.'3'] = 'foo';
101 $this->resource->isFresh(time()),
102 '->isFresh() returns false if a variable has been added'
106 public function testSerializeUnserialize()
108 $this->assertEquals($this->resource, unserialize(serialize($this->resource)));