FileLoaderTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. namespace Symfony\Tests\Component\Routing\Loader;
  10. use Symfony\Component\Routing\Loader\FileLoader;
  11. class FileLoaderTest extends \PHPUnit_Framework_TestCase
  12. {
  13. /**
  14. * @covers Symfony\Component\Routing\Loader\FileLoader::__construct
  15. */
  16. public function testConstructor()
  17. {
  18. $loader = new ProjectLoader(__DIR__);
  19. $this->assertEquals(array(__DIR__), $loader->paths, '__construct() takes a path as its second argument');
  20. $loader = new ProjectLoader(array(__DIR__, __DIR__));
  21. $this->assertEquals(array(__DIR__, __DIR__), $loader->paths, '__construct() takes an array of paths as its second argument');
  22. }
  23. /**
  24. * @covers Symfony\Component\Routing\Loader\FileLoader::GetAbsolutePath
  25. * @covers Symfony\Component\Routing\Loader\FileLoader::isAbsolutePath
  26. */
  27. public function testGetAbsolutePath()
  28. {
  29. $loader = new ProjectLoader(array(__DIR__.'/../Fixtures'));
  30. $this->assertEquals('/foo.xml', $loader->getAbsolutePath('/foo.xml'), '->getAbsolutePath() return the path unmodified if it is already an absolute path');
  31. $this->assertEquals('c:\\\\foo.xml', $loader->getAbsolutePath('c:\\\\foo.xml'), '->getAbsolutePath() return the path unmodified if it is already an absolute path');
  32. $this->assertEquals('c:/foo.xml', $loader->getAbsolutePath('c:/foo.xml'), '->getAbsolutePath() return the path unmodified if it is already an absolute path');
  33. $this->assertEquals('\\server\\foo.xml', $loader->getAbsolutePath('\\server\\foo.xml'), '->getAbsolutePath() return the path unmodified if it is already an absolute path');
  34. $this->assertEquals(__DIR__.DIRECTORY_SEPARATOR.'FileLoaderTest.php', $loader->getAbsolutePath('FileLoaderTest.php', __DIR__), '->getAbsolutePath() returns an absolute filename if the file exists in the current path');
  35. $this->assertEquals(__DIR__.'/../Fixtures/foo.xml', $loader->getAbsolutePath('foo.xml', __DIR__), '->getAbsolutePath() returns an absolute filename if the file exists in one of the paths given in the constructor');
  36. $this->assertEquals('foobar.xml', $loader->getAbsolutePath('foobar.xml', __DIR__), '->getAbsolutePath() returns the path unmodified if it is unable to find it in the given paths');
  37. }
  38. }
  39. class ProjectLoader extends FileLoader
  40. {
  41. public $paths;
  42. public function load($resource)
  43. {
  44. }
  45. public function supports($resource)
  46. {
  47. return true;
  48. }
  49. public function getAbsolutePath($file, $currentPath = null)
  50. {
  51. return parent::getAbsolutePath($file, $currentPath);
  52. }
  53. }