No Description

EnvParametersResourceTest.php 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpKernel\Tests\Config;
  11. use Symfony\Component\HttpKernel\Config\EnvParametersResource;
  12. class EnvParametersResourceTest extends \PHPUnit_Framework_TestCase
  13. {
  14. protected $prefix = '__DUMMY_';
  15. protected $initialEnv;
  16. protected $resource;
  17. protected function setUp()
  18. {
  19. $this->initialEnv = array(
  20. $this->prefix.'1' => 'foo',
  21. $this->prefix.'2' => 'bar',
  22. );
  23. foreach ($this->initialEnv as $key => $value) {
  24. $_SERVER[$key] = $value;
  25. }
  26. $this->resource = new EnvParametersResource($this->prefix);
  27. }
  28. protected function tearDown()
  29. {
  30. foreach ($_SERVER as $key => $value) {
  31. if (0 === strpos($key, $this->prefix)) {
  32. unset($_SERVER[$key]);
  33. }
  34. }
  35. }
  36. public function testGetResource()
  37. {
  38. $this->assertSame(
  39. array('prefix' => $this->prefix, 'variables' => $this->initialEnv),
  40. $this->resource->getResource(),
  41. '->getResource() returns the resource'
  42. );
  43. }
  44. public function testToString()
  45. {
  46. $this->assertSame(
  47. serialize(array('prefix' => $this->prefix, 'variables' => $this->initialEnv)),
  48. (string) $this->resource
  49. );
  50. }
  51. public function testIsFreshNotChanged()
  52. {
  53. $this->assertTrue(
  54. $this->resource->isFresh(time()),
  55. '->isFresh() returns true if the variables have not changed'
  56. );
  57. }
  58. public function testIsFreshValueChanged()
  59. {
  60. reset($this->initialEnv);
  61. $_SERVER[key($this->initialEnv)] = 'baz';
  62. $this->assertFalse(
  63. $this->resource->isFresh(time()),
  64. '->isFresh() returns false if a variable has been changed'
  65. );
  66. }
  67. public function testIsFreshValueRemoved()
  68. {
  69. reset($this->initialEnv);
  70. unset($_SERVER[key($this->initialEnv)]);
  71. $this->assertFalse(
  72. $this->resource->isFresh(time()),
  73. '->isFresh() returns false if a variable has been removed'
  74. );
  75. }
  76. public function testIsFreshValueAdded()
  77. {
  78. $_SERVER[$this->prefix.'3'] = 'foo';
  79. $this->assertFalse(
  80. $this->resource->isFresh(time()),
  81. '->isFresh() returns false if a variable has been added'
  82. );
  83. }
  84. public function testSerializeUnserialize()
  85. {
  86. $this->assertEquals($this->resource, unserialize(serialize($this->resource)));
  87. }
  88. }