Yaffs site version 1.1
[yaffs-website] / vendor / symfony / config / Tests / Resource / FileResourceTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Config\Tests\Resource;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Config\Resource\FileResource;
16
17 class FileResourceTest extends TestCase
18 {
19     protected $resource;
20     protected $file;
21     protected $time;
22
23     protected function setUp()
24     {
25         $this->file = realpath(sys_get_temp_dir()).'/tmp.xml';
26         $this->time = time();
27         touch($this->file, $this->time);
28         $this->resource = new FileResource($this->file);
29     }
30
31     protected function tearDown()
32     {
33         unlink($this->file);
34     }
35
36     public function testGetResource()
37     {
38         $this->assertSame(realpath($this->file), $this->resource->getResource(), '->getResource() returns the path to the resource');
39     }
40
41     public function testToString()
42     {
43         $this->assertSame(realpath($this->file), (string) $this->resource);
44     }
45
46     public function testIsFresh()
47     {
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');
51
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');
54     }
55
56     public function testSerializeUnserialize()
57     {
58         $unserialized = unserialize(serialize($this->resource));
59
60         $this->assertSame(realpath($this->file), $this->resource->getResource());
61     }
62 }