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\GlobResource;
17 class GlobResourceTest extends TestCase
19 protected function tearDown()
21 $dir = \dirname(__DIR__).'/Fixtures';
22 @rmdir($dir.'/TmpGlob');
23 @unlink($dir.'/TmpGlob');
24 @unlink($dir.'/Resource/TmpGlob');
25 touch($dir.'/Resource/.hiddenFile');
28 public function testIterator()
30 $dir = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures';
31 $resource = new GlobResource($dir, '/Resource', true);
33 $paths = iterator_to_array($resource);
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());
40 $resource = new GlobResource($dir, '/**/Resource', true);
42 $paths = iterator_to_array($resource);
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());
50 public function testIsFreshNonRecursiveDetectsNewFile()
52 $dir = \dirname(__DIR__).'/Fixtures';
53 $resource = new GlobResource($dir, '/*', false);
55 $this->assertTrue($resource->isFresh(0));
57 mkdir($dir.'/TmpGlob');
58 $this->assertTrue($resource->isFresh(0));
60 rmdir($dir.'/TmpGlob');
61 $this->assertTrue($resource->isFresh(0));
63 touch($dir.'/TmpGlob');
64 $this->assertFalse($resource->isFresh(0));
66 unlink($dir.'/TmpGlob');
67 $this->assertTrue($resource->isFresh(0));
70 public function testIsFreshNonRecursiveDetectsRemovedFile()
72 $dir = \dirname(__DIR__).'/Fixtures';
73 $resource = new GlobResource($dir, '/*', false);
75 touch($dir.'/TmpGlob');
76 touch($dir.'/.TmpGlob');
77 $this->assertTrue($resource->isFresh(0));
79 unlink($dir.'/.TmpGlob');
80 $this->assertTrue($resource->isFresh(0));
82 unlink($dir.'/TmpGlob');
83 $this->assertFalse($resource->isFresh(0));
86 public function testIsFreshRecursiveDetectsRemovedFile()
88 $dir = \dirname(__DIR__).'/Fixtures';
89 $resource = new GlobResource($dir, '/*', true);
91 touch($dir.'/Resource/TmpGlob');
92 $this->assertTrue($resource->isFresh(0));
94 unlink($dir.'/Resource/TmpGlob');
95 $this->assertFalse($resource->isFresh(0));
97 touch($dir.'/Resource/TmpGlob');
98 $this->assertTrue($resource->isFresh(0));
100 unlink($dir.'/Resource/.hiddenFile');
101 $this->assertTrue($resource->isFresh(0));
104 public function testIsFreshRecursiveDetectsNewFile()
106 $dir = \dirname(__DIR__).'/Fixtures';
107 $resource = new GlobResource($dir, '/*', true);
109 $this->assertTrue($resource->isFresh(0));
111 touch($dir.'/Resource/TmpGlob');
112 $this->assertFalse($resource->isFresh(0));