Yaffs site version 1.1
[yaffs-website] / vendor / symfony / config / Tests / FileLocatorTest.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;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Config\FileLocator;
16
17 class FileLocatorTest extends TestCase
18 {
19     /**
20      * @dataProvider getIsAbsolutePathTests
21      */
22     public function testIsAbsolutePath($path)
23     {
24         $loader = new FileLocator(array());
25         $r = new \ReflectionObject($loader);
26         $m = $r->getMethod('isAbsolutePath');
27         $m->setAccessible(true);
28
29         $this->assertTrue($m->invoke($loader, $path), '->isAbsolutePath() returns true for an absolute path');
30     }
31
32     public function getIsAbsolutePathTests()
33     {
34         return array(
35             array('/foo.xml'),
36             array('c:\\\\foo.xml'),
37             array('c:/foo.xml'),
38             array('\\server\\foo.xml'),
39             array('https://server/foo.xml'),
40             array('phar://server/foo.xml'),
41         );
42     }
43
44     public function testLocate()
45     {
46         $loader = new FileLocator(__DIR__.'/Fixtures');
47
48         $this->assertEquals(
49             __DIR__.DIRECTORY_SEPARATOR.'FileLocatorTest.php',
50             $loader->locate('FileLocatorTest.php', __DIR__),
51             '->locate() returns the absolute filename if the file exists in the given path'
52         );
53
54         $this->assertEquals(
55             __DIR__.'/Fixtures'.DIRECTORY_SEPARATOR.'foo.xml',
56             $loader->locate('foo.xml', __DIR__),
57             '->locate() returns the absolute filename if the file exists in one of the paths given in the constructor'
58         );
59
60         $this->assertEquals(
61             __DIR__.'/Fixtures'.DIRECTORY_SEPARATOR.'foo.xml',
62             $loader->locate(__DIR__.'/Fixtures'.DIRECTORY_SEPARATOR.'foo.xml', __DIR__),
63             '->locate() returns the absolute filename if the file exists in one of the paths given in the constructor'
64         );
65
66         $loader = new FileLocator(array(__DIR__.'/Fixtures', __DIR__.'/Fixtures/Again'));
67
68         $this->assertEquals(
69             array(__DIR__.'/Fixtures'.DIRECTORY_SEPARATOR.'foo.xml', __DIR__.'/Fixtures/Again'.DIRECTORY_SEPARATOR.'foo.xml'),
70             $loader->locate('foo.xml', __DIR__, false),
71             '->locate() returns an array of absolute filenames'
72         );
73
74         $this->assertEquals(
75             array(__DIR__.'/Fixtures'.DIRECTORY_SEPARATOR.'foo.xml', __DIR__.'/Fixtures/Again'.DIRECTORY_SEPARATOR.'foo.xml'),
76             $loader->locate('foo.xml', __DIR__.'/Fixtures', false),
77             '->locate() returns an array of absolute filenames'
78         );
79
80         $loader = new FileLocator(__DIR__.'/Fixtures/Again');
81
82         $this->assertEquals(
83             array(__DIR__.'/Fixtures'.DIRECTORY_SEPARATOR.'foo.xml', __DIR__.'/Fixtures/Again'.DIRECTORY_SEPARATOR.'foo.xml'),
84             $loader->locate('foo.xml', __DIR__.'/Fixtures', false),
85             '->locate() returns an array of absolute filenames'
86         );
87     }
88
89     /**
90      * @expectedException \InvalidArgumentException
91      * @expectedExceptionMessage The file "foobar.xml" does not exist
92      */
93     public function testLocateThrowsAnExceptionIfTheFileDoesNotExists()
94     {
95         $loader = new FileLocator(array(__DIR__.'/Fixtures'));
96
97         $loader->locate('foobar.xml', __DIR__);
98     }
99
100     /**
101      * @expectedException \InvalidArgumentException
102      */
103     public function testLocateThrowsAnExceptionIfTheFileDoesNotExistsInAbsolutePath()
104     {
105         $loader = new FileLocator(array(__DIR__.'/Fixtures'));
106
107         $loader->locate(__DIR__.'/Fixtures/foobar.xml', __DIR__);
108     }
109
110     /**
111      * @expectedException \InvalidArgumentException
112      * @expectedExceptionMessage An empty file name is not valid to be located.
113      */
114     public function testLocateEmpty()
115     {
116         $loader = new FileLocator(array(__DIR__.'/Fixtures'));
117
118         $loader->locate(null, __DIR__);
119     }
120 }