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