Added the Search API Synonym module to deal specifically with licence and license...
[yaffs-website] / vendor / symfony / config / Tests / Resource / GlobResourceTest.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\GlobResource;
16
17 class GlobResourceTest extends TestCase
18 {
19     protected function tearDown()
20     {
21         $dir = \dirname(__DIR__).'/Fixtures';
22         @rmdir($dir.'/TmpGlob');
23         @unlink($dir.'/TmpGlob');
24         @unlink($dir.'/Resource/TmpGlob');
25         touch($dir.'/Resource/.hiddenFile');
26     }
27
28     public function testIterator()
29     {
30         $dir = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures';
31         $resource = new GlobResource($dir, '/Resource', true);
32
33         $paths = iterator_to_array($resource);
34
35         $file = $dir.'/Resource'.\DIRECTORY_SEPARATOR.'ConditionalClass.php';
36         $this->assertEquals(array($file => new \SplFileInfo($file)), $paths);
37         $this->assertInstanceOf('SplFileInfo', current($paths));
38         $this->assertSame($dir, $resource->getPrefix());
39
40         $resource = new GlobResource($dir, '/**/Resource', true);
41
42         $paths = iterator_to_array($resource);
43
44         $file = $dir.\DIRECTORY_SEPARATOR.'Resource'.\DIRECTORY_SEPARATOR.'ConditionalClass.php';
45         $this->assertEquals(array($file => $file), $paths);
46         $this->assertInstanceOf('SplFileInfo', current($paths));
47         $this->assertSame($dir, $resource->getPrefix());
48     }
49
50     public function testIsFreshNonRecursiveDetectsNewFile()
51     {
52         $dir = \dirname(__DIR__).'/Fixtures';
53         $resource = new GlobResource($dir, '/*', false);
54
55         $this->assertTrue($resource->isFresh(0));
56
57         mkdir($dir.'/TmpGlob');
58         $this->assertTrue($resource->isFresh(0));
59
60         rmdir($dir.'/TmpGlob');
61         $this->assertTrue($resource->isFresh(0));
62
63         touch($dir.'/TmpGlob');
64         $this->assertFalse($resource->isFresh(0));
65
66         unlink($dir.'/TmpGlob');
67         $this->assertTrue($resource->isFresh(0));
68     }
69
70     public function testIsFreshNonRecursiveDetectsRemovedFile()
71     {
72         $dir = \dirname(__DIR__).'/Fixtures';
73         $resource = new GlobResource($dir, '/*', false);
74
75         touch($dir.'/TmpGlob');
76         touch($dir.'/.TmpGlob');
77         $this->assertTrue($resource->isFresh(0));
78
79         unlink($dir.'/.TmpGlob');
80         $this->assertTrue($resource->isFresh(0));
81
82         unlink($dir.'/TmpGlob');
83         $this->assertFalse($resource->isFresh(0));
84     }
85
86     public function testIsFreshRecursiveDetectsRemovedFile()
87     {
88         $dir = \dirname(__DIR__).'/Fixtures';
89         $resource = new GlobResource($dir, '/*', true);
90
91         touch($dir.'/Resource/TmpGlob');
92         $this->assertTrue($resource->isFresh(0));
93
94         unlink($dir.'/Resource/TmpGlob');
95         $this->assertFalse($resource->isFresh(0));
96
97         touch($dir.'/Resource/TmpGlob');
98         $this->assertTrue($resource->isFresh(0));
99
100         unlink($dir.'/Resource/.hiddenFile');
101         $this->assertTrue($resource->isFresh(0));
102     }
103
104     public function testIsFreshRecursiveDetectsNewFile()
105     {
106         $dir = \dirname(__DIR__).'/Fixtures';
107         $resource = new GlobResource($dir, '/*', true);
108
109         $this->assertTrue($resource->isFresh(0));
110
111         touch($dir.'/Resource/TmpGlob');
112         $this->assertFalse($resource->isFresh(0));
113     }
114 }