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;
17 class EnvParametersResourceTest extends TestCase
19 protected $prefix = '__DUMMY_';
20 protected $initialEnv;
23 protected function setUp()
25 $this->initialEnv = array(
26 $this->prefix.'1' => 'foo',
27 $this->prefix.'2' => 'bar',
30 foreach ($this->initialEnv as $key => $value) {
31 $_SERVER[$key] = $value;
34 $this->resource = new EnvParametersResource($this->prefix);
37 protected function tearDown()
39 foreach ($_SERVER as $key => $value) {
40 if (0 === strpos($key, $this->prefix)) {
41 unset($_SERVER[$key]);
46 public function testGetResource()
49 array('prefix' => $this->prefix, 'variables' => $this->initialEnv),
50 $this->resource->getResource(),
51 '->getResource() returns the resource'
55 public function testToString()
58 serialize(array('prefix' => $this->prefix, 'variables' => $this->initialEnv)),
59 (string) $this->resource
63 public function testIsFreshNotChanged()
66 $this->resource->isFresh(time()),
67 '->isFresh() returns true if the variables have not changed'
71 public function testIsFreshValueChanged()
73 reset($this->initialEnv);
74 $_SERVER[key($this->initialEnv)] = 'baz';
77 $this->resource->isFresh(time()),
78 '->isFresh() returns false if a variable has been changed'
82 public function testIsFreshValueRemoved()
84 reset($this->initialEnv);
85 unset($_SERVER[key($this->initialEnv)]);
88 $this->resource->isFresh(time()),
89 '->isFresh() returns false if a variable has been removed'
93 public function testIsFreshValueAdded()
95 $_SERVER[$this->prefix.'3'] = 'foo';
98 $this->resource->isFresh(time()),
99 '->isFresh() returns false if a variable has been added'
103 public function testSerializeUnserialize()
105 $this->assertEquals($this->resource, unserialize(serialize($this->resource)));