FileResourceTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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\Config\Tests\Resource;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Config\Resource\FileResource;
  13. class FileResourceTest extends TestCase
  14. {
  15. protected $resource;
  16. protected $file;
  17. protected $time;
  18. protected function setUp()
  19. {
  20. $this->file = realpath(sys_get_temp_dir()).'/tmp.xml';
  21. $this->time = time();
  22. touch($this->file, $this->time);
  23. $this->resource = new FileResource($this->file);
  24. }
  25. protected function tearDown()
  26. {
  27. unlink($this->file);
  28. }
  29. public function testGetResource()
  30. {
  31. $this->assertSame(realpath($this->file), $this->resource->getResource(), '->getResource() returns the path to the resource');
  32. }
  33. public function testToString()
  34. {
  35. $this->assertSame(realpath($this->file), (string) $this->resource);
  36. }
  37. public function testIsFresh()
  38. {
  39. $this->assertTrue($this->resource->isFresh($this->time), '->isFresh() returns true if the resource has not changed in same second');
  40. $this->assertTrue($this->resource->isFresh($this->time + 10), '->isFresh() returns true if the resource has not changed');
  41. $this->assertFalse($this->resource->isFresh($this->time - 86400), '->isFresh() returns false if the resource has been updated');
  42. $resource = new FileResource('/____foo/foobar'.mt_rand(1, 999999));
  43. $this->assertFalse($resource->isFresh($this->time), '->isFresh() returns false if the resource does not exist');
  44. }
  45. public function testSerializeUnserialize()
  46. {
  47. $unserialized = unserialize(serialize($this->resource));
  48. $this->assertSame(realpath($this->file), $this->resource->getResource());
  49. }
  50. }