Yaffs site version 1.1
[yaffs-website] / vendor / symfony / config / Tests / Resource / FileExistenceResourceTest.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\FileExistenceResource;
16
17 class FileExistenceResourceTest 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         $this->resource = new FileExistenceResource($this->file);
28     }
29
30     protected function tearDown()
31     {
32         if (file_exists($this->file)) {
33             unlink($this->file);
34         }
35     }
36
37     public function testToString()
38     {
39         $this->assertSame($this->file, (string) $this->resource);
40     }
41
42     public function testGetResource()
43     {
44         $this->assertSame($this->file, $this->resource->getResource(), '->getResource() returns the path to the resource');
45     }
46
47     public function testIsFreshWithExistingResource()
48     {
49         touch($this->file, $this->time);
50         $serialized = serialize(new FileExistenceResource($this->file));
51
52         $resource = unserialize($serialized);
53         $this->assertTrue($resource->isFresh($this->time), '->isFresh() returns true if the resource is still present');
54
55         unlink($this->file);
56         $resource = unserialize($serialized);
57         $this->assertFalse($resource->isFresh($this->time), '->isFresh() returns false if the resource has been deleted');
58     }
59
60     public function testIsFreshWithAbsentResource()
61     {
62         $serialized = serialize(new FileExistenceResource($this->file));
63
64         $resource = unserialize($serialized);
65         $this->assertTrue($resource->isFresh($this->time), '->isFresh() returns true if the resource is still absent');
66
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');
70     }
71 }