Added the Search API Synonym module to deal specifically with licence and license...
[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 = 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         if (!file_exists($this->file)) {
34             return;
35         }
36
37         unlink($this->file);
38     }
39
40     public function testGetResource()
41     {
42         $this->assertSame(realpath($this->file), $this->resource->getResource(), '->getResource() returns the path to the resource');
43     }
44
45     public function testGetResourceWithScheme()
46     {
47         $resource = new FileResource('file://'.$this->file);
48         $this->assertSame('file://'.$this->file, $resource->getResource(), '->getResource() returns the path to the schemed resource');
49     }
50
51     public function testToString()
52     {
53         $this->assertSame(realpath($this->file), (string) $this->resource);
54     }
55
56     /**
57      * @expectedException \InvalidArgumentException
58      * @expectedExceptionMessageRegExp /The file ".*" does not exist./
59      */
60     public function testResourceDoesNotExist()
61     {
62         $resource = new FileResource('/____foo/foobar'.mt_rand(1, 999999));
63     }
64
65     public function testIsFresh()
66     {
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');
70     }
71
72     public function testIsFreshForDeletedResources()
73     {
74         unlink($this->file);
75
76         $this->assertFalse($this->resource->isFresh($this->time), '->isFresh() returns false if the resource does not exist');
77     }
78
79     public function testSerializeUnserialize()
80     {
81         $unserialized = unserialize(serialize($this->resource));
82
83         $this->assertSame(realpath($this->file), $this->resource->getResource());
84     }
85 }