FileResourceTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 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. public function testGetResource()
  27. {
  28. $this->assertSame(realpath($this->file), $this->resource->getResource(), '->getResource() returns the path to the resource');
  29. }
  30. public function testToString()
  31. {
  32. $this->assertSame(realpath($this->file), (string) $this->resource);
  33. }
  34. public function testIsFresh()
  35. {
  36. $this->assertTrue($this->resource->isFresh(time() + 10), '->isFresh() returns true if the resource has not changed');
  37. $this->assertFalse($this->resource->isFresh(time() - 86400), '->isFresh() returns false if the resource has been updated');
  38. $resource = new FileResource('/____foo/foobar'.rand(1, 999999));
  39. $this->assertFalse($resource->isFresh(time()), '->isFresh() returns false if the resource does not exist');
  40. }
  41. public function testSerializeUnserialize()
  42. {
  43. $unserialized = unserialize(serialize($this->resource));
  44. $this->assertSame($this->file, $this->resource->getResource());
  45. }
  46. }