4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Config\Tests\Resource;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Config\Resource\FileExistenceResource;
17 class FileExistenceResourceTest extends TestCase
23 protected function setUp()
25 $this->file = realpath(sys_get_temp_dir()).'/tmp.xml';
27 $this->resource = new FileExistenceResource($this->file);
30 protected function tearDown()
32 if (file_exists($this->file)) {
37 public function testToString()
39 $this->assertSame($this->file, (string) $this->resource);
42 public function testGetResource()
44 $this->assertSame($this->file, $this->resource->getResource(), '->getResource() returns the path to the resource');
47 public function testIsFreshWithExistingResource()
49 touch($this->file, $this->time);
50 $serialized = serialize(new FileExistenceResource($this->file));
52 $resource = unserialize($serialized);
53 $this->assertTrue($resource->isFresh($this->time), '->isFresh() returns true if the resource is still present');
56 $resource = unserialize($serialized);
57 $this->assertFalse($resource->isFresh($this->time), '->isFresh() returns false if the resource has been deleted');
60 public function testIsFreshWithAbsentResource()
62 $serialized = serialize(new FileExistenceResource($this->file));
64 $resource = unserialize($serialized);
65 $this->assertTrue($resource->isFresh($this->time), '->isFresh() returns true if the resource is still absent');
67 touch($this->file, $this->time);
68 $resource = unserialize($serialized);
69 $this->assertFalse($resource->isFresh($this->time), '->isFresh() returns false if the resource has been created');