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;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Config\FileLocator;
17 class FileLocatorTest extends TestCase
20 * @dataProvider getIsAbsolutePathTests
22 public function testIsAbsolutePath($path)
24 $loader = new FileLocator(array());
25 $r = new \ReflectionObject($loader);
26 $m = $r->getMethod('isAbsolutePath');
27 $m->setAccessible(true);
29 $this->assertTrue($m->invoke($loader, $path), '->isAbsolutePath() returns true for an absolute path');
32 public function getIsAbsolutePathTests()
36 array('c:\\\\foo.xml'),
38 array('\\server\\foo.xml'),
39 array('https://server/foo.xml'),
40 array('phar://server/foo.xml'),
44 public function testLocate()
46 $loader = new FileLocator(__DIR__.'/Fixtures');
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'
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'
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'
66 $loader = new FileLocator(array(__DIR__.'/Fixtures', __DIR__.'/Fixtures/Again'));
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'
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'
80 $loader = new FileLocator(__DIR__.'/Fixtures/Again');
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'
90 * @expectedException \InvalidArgumentException
91 * @expectedExceptionMessage The file "foobar.xml" does not exist
93 public function testLocateThrowsAnExceptionIfTheFileDoesNotExists()
95 $loader = new FileLocator(array(__DIR__.'/Fixtures'));
97 $loader->locate('foobar.xml', __DIR__);
101 * @expectedException \InvalidArgumentException
103 public function testLocateThrowsAnExceptionIfTheFileDoesNotExistsInAbsolutePath()
105 $loader = new FileLocator(array(__DIR__.'/Fixtures'));
107 $loader->locate(__DIR__.'/Fixtures/foobar.xml', __DIR__);
111 * @expectedException \InvalidArgumentException
112 * @expectedExceptionMessage An empty file name is not valid to be located.
114 public function testLocateEmpty()
116 $loader = new FileLocator(array(__DIR__.'/Fixtures'));
118 $loader->locate(null, __DIR__);