FileResourceTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. namespace Symfony\Tests\Component\DependencyInjection\Resource;
  10. use Symfony\Component\DependencyInjection\Resource\FileResource;
  11. class FileResourceTest extends \PHPUnit_Framework_TestCase
  12. {
  13. protected $resource;
  14. protected $file;
  15. protected function setUp()
  16. {
  17. $this->file = sys_get_temp_dir().'/tmp.xml';
  18. touch($this->file);
  19. $this->resource = new FileResource($this->file);
  20. }
  21. protected function tearDown()
  22. {
  23. unlink($this->file);
  24. }
  25. /**
  26. * @covers Symfony\Component\DependencyInjection\Resource\FileResource::getResource
  27. */
  28. public function testGetResource()
  29. {
  30. $this->assertEquals(realpath($this->file), $this->resource->getResource(), '->getResource() returns the path to the resource');
  31. }
  32. /**
  33. * @covers Symfony\Component\DependencyInjection\Resource\FileResource::isUptodate
  34. */
  35. public function testIsUptodate()
  36. {
  37. $this->assertTrue($this->resource->isUptodate(time() + 10), '->isUptodate() returns true if the resource has not changed');
  38. $this->assertFalse($this->resource->isUptodate(time() - 86400), '->isUptodate() returns false if the resource has been updated');
  39. $resource = new FileResource('/____foo/foobar'.rand(1, 999999));
  40. $this->assertFalse($resource->isUptodate(time()), '->isUptodate() returns false if the resource does not exist');
  41. }
  42. }