FileResourceTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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\Tests\Component\Config\Resource;
  11. use Symfony\Component\Config\Resource\FileResource;
  12. class FileResourceTest extends \PHPUnit_Framework_TestCase
  13. {
  14. protected $resource;
  15. protected $file;
  16. protected function setUp()
  17. {
  18. $this->file = sys_get_temp_dir().'/tmp.xml';
  19. touch($this->file);
  20. $this->resource = new FileResource($this->file);
  21. }
  22. protected function tearDown()
  23. {
  24. unlink($this->file);
  25. }
  26. /**
  27. * @covers Symfony\Component\Config\Resource\FileResource::getResource
  28. */
  29. public function testGetResource()
  30. {
  31. $this->assertEquals(realpath($this->file), $this->resource->getResource(), '->getResource() returns the path to the resource');
  32. }
  33. /**
  34. * @covers Symfony\Component\Config\Resource\FileResource::isFresh
  35. */
  36. public function testIsFresh()
  37. {
  38. $this->assertTrue($this->resource->isFresh(time() + 10), '->isFresh() returns true if the resource has not changed');
  39. $this->assertFalse($this->resource->isFresh(time() - 86400), '->isFresh() returns false if the resource has been updated');
  40. $resource = new FileResource('/____foo/foobar'.rand(1, 999999));
  41. $this->assertFalse($resource->isFresh(time()), '->isFresh() returns false if the resource does not exist');
  42. }
  43. }