FileLocatorTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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(array(__DIR__.'/Fixtures'));
  37. $this->assertEquals(__DIR__.DIRECTORY_SEPARATOR.'FileLocatorTest.php', $loader->locate('FileLocatorTest.php', __DIR__), '->getAbsolutePath() returns an absolute filename if the file exists in the current path');
  38. $this->assertEquals(__DIR__.'/Fixtures'.DIRECTORY_SEPARATOR.'foo.xml', $loader->locate('foo.xml', __DIR__), '->getAbsolutePath() returns an absolute filename if the file exists in one of the paths given in the constructor');
  39. }
  40. /**
  41. * @expectedException \InvalidArgumentException
  42. */
  43. public function testLocateThrowsAnExceptionIfTheFileDoesNotExists()
  44. {
  45. $loader = new FileLocator(array(__DIR__.'/Fixtures'));
  46. $loader->locate('foobar.xml', __DIR__);
  47. }
  48. }