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 = sys_get_temp_dir().'/tmp.xml';
27 touch($this->file, $this->time);
28 $this->resource = new FileResource($this->file);
31 protected function tearDown()
33 if (!file_exists($this->file)) {
40 public function testGetResource()
42 $this->assertSame(realpath($this->file), $this->resource->getResource(), '->getResource() returns the path to the resource');
45 public function testGetResourceWithScheme()
47 $resource = new FileResource('file://'.$this->file);
48 $this->assertSame('file://'.$this->file, $resource->getResource(), '->getResource() returns the path to the schemed resource');
51 public function testToString()
53 $this->assertSame(realpath($this->file), (string) $this->resource);
57 * @expectedException \InvalidArgumentException
58 * @expectedExceptionMessageRegExp /The file ".*" does not exist./
60 public function testResourceDoesNotExist()
62 $resource = new FileResource('/____foo/foobar'.mt_rand(1, 999999));
65 public function testIsFresh()
67 $this->assertTrue($this->resource->isFresh($this->time), '->isFresh() returns true if the resource has not changed in same second');
68 $this->assertTrue($this->resource->isFresh($this->time + 10), '->isFresh() returns true if the resource has not changed');
69 $this->assertFalse($this->resource->isFresh($this->time - 86400), '->isFresh() returns false if the resource has been updated');
72 public function testIsFreshForDeletedResources()
76 $this->assertFalse($this->resource->isFresh($this->time), '->isFresh() returns false if the resource does not exist');
79 public function testSerializeUnserialize()
81 $unserialized = unserialize(serialize($this->resource));
83 $this->assertSame(realpath($this->file), $this->resource->getResource());