FileLocatorTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Component\Config;
  11. use Symfony\Component\Config\FileLocator;
  12. class FileLocatorTest extends \PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * @dataProvider getIsAbsolutePathTests
  16. */
  17. public function testIsAbsolutePath($path)
  18. {
  19. $loader = new FileLocator(array());
  20. $r = new \ReflectionObject($loader);
  21. $m = $r->getMethod('isAbsolutePath');
  22. $m->setAccessible(true);
  23. $this->assertTrue($m->invoke($loader, $path), '->isAbsolutePath() returns true for an absolute path');
  24. }
  25. public function getIsAbsolutePathTests()
  26. {
  27. return array(
  28. array('/foo.xml'),
  29. array('c:\\\\foo.xml'),
  30. array('c:/foo.xml'),
  31. array('\\server\\foo.xml'),
  32. );
  33. }
  34. public function testLocate()
  35. {
  36. $loader = new FileLocator(__DIR__.'/Fixtures');
  37. $this->assertEquals(
  38. __DIR__.DIRECTORY_SEPARATOR.'FileLocatorTest.php',
  39. $loader->locate('FileLocatorTest.php', __DIR__),
  40. '->locate() returns the absolute filename if the file exists in the given path'
  41. );
  42. $this->assertEquals(
  43. __DIR__.'/Fixtures'.DIRECTORY_SEPARATOR.'foo.xml',
  44. $loader->locate('foo.xml', __DIR__),
  45. '->locate() returns the absolute filename if the file exists in one of the paths given in the constructor'
  46. );
  47. $loader = new FileLocator(array(__DIR__.'/Fixtures', __DIR__.'/Fixtures/Again'));
  48. $this->assertEquals(
  49. array(__DIR__.'/Fixtures'.DIRECTORY_SEPARATOR.'foo.xml', __DIR__.'/Fixtures/Again'.DIRECTORY_SEPARATOR.'foo.xml'),
  50. $loader->locate('foo.xml', __DIR__, false),
  51. '->locate() returns an array of absolute filenames'
  52. );
  53. }
  54. /**
  55. * @expectedException \InvalidArgumentException
  56. */
  57. public function testLocateThrowsAnExceptionIfTheFileDoesNotExists()
  58. {
  59. $loader = new FileLocator(array(__DIR__.'/Fixtures'));
  60. $loader->locate('foobar.xml', __DIR__);
  61. }
  62. }