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\FileResource;
17 class FileResourceTest extends TestCase
23 protected function setUp()
25 $this->file = realpath(sys_get_temp_dir()).'/tmp.xml';
27 touch($this->file, $this->time);
28 $this->resource = new FileResource($this->file);
31 protected function tearDown()
36 public function testGetResource()
38 $this->assertSame(realpath($this->file), $this->resource->getResource(), '->getResource() returns the path to the resource');
41 public function testToString()
43 $this->assertSame(realpath($this->file), (string) $this->resource);
46 public function testIsFresh()
48 $this->assertTrue($this->resource->isFresh($this->time), '->isFresh() returns true if the resource has not changed in same second');
49 $this->assertTrue($this->resource->isFresh($this->time + 10), '->isFresh() returns true if the resource has not changed');
50 $this->assertFalse($this->resource->isFresh($this->time - 86400), '->isFresh() returns false if the resource has been updated');
52 $resource = new FileResource('/____foo/foobar'.mt_rand(1, 999999));
53 $this->assertFalse($resource->isFresh($this->time), '->isFresh() returns false if the resource does not exist');
56 public function testSerializeUnserialize()
58 $unserialized = unserialize(serialize($this->resource));
60 $this->assertSame(realpath($this->file), $this->resource->getResource());