FileLoaderTest.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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\DependencyInjection\Loader;
  11. use Symfony\Component\DependencyInjection\ContainerBuilder;
  12. use Symfony\Component\DependencyInjection\Loader\FileLoader;
  13. class FileLoaderTest extends \PHPUnit_Framework_TestCase
  14. {
  15. /**
  16. * @covers Symfony\Component\DependencyInjection\Loader\FileLoader::__construct
  17. */
  18. public function testConstructor()
  19. {
  20. $loader = new ProjectLoader(new ContainerBuilder(), __DIR__);
  21. $this->assertEquals(array(__DIR__), $loader->paths, '__construct() takes a path as its second argument');
  22. $loader = new ProjectLoader(new ContainerBuilder(), array(__DIR__, __DIR__));
  23. $this->assertEquals(array(__DIR__, __DIR__), $loader->paths, '__construct() takes an array of paths as its second argument');
  24. }
  25. /**
  26. * @covers Symfony\Component\DependencyInjection\Loader\FileLoader::GetAbsolutePath
  27. */
  28. public function testGetAbsolutePath()
  29. {
  30. $loader = new ProjectLoader(new ContainerBuilder(), array(__DIR__.'/../Fixtures/containers'));
  31. $this->assertEquals('/foo.xml', $loader->getAbsolutePath('/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('c:/foo.xml', $loader->getAbsolutePath('c:/foo.xml'), '->getAbsolutePath() return the path unmodified if it is already an absolute path');
  34. $this->assertEquals('\\server\\foo.xml', $loader->getAbsolutePath('\\server\\foo.xml'), '->getAbsolutePath() return the path unmodified if it is already an absolute path');
  35. $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');
  36. $this->assertEquals(__DIR__.'/../Fixtures/containers'.DIRECTORY_SEPARATOR.'container10.php', $loader->getAbsolutePath('container10.php', __DIR__), '->getAbsolutePath() returns an absolute filename if the file exists in one of the paths given in the constructor');
  37. $this->assertEquals('foo.xml', $loader->getAbsolutePath('foo.xml', __DIR__), '->getAbsolutePath() returns the path unmodified if it is unable to find it in the given paths');
  38. }
  39. }
  40. class ProjectLoader extends FileLoader
  41. {
  42. public $paths;
  43. public function load($resource, ContainerBuilder $container = null)
  44. {
  45. }
  46. public function supports($resource)
  47. {
  48. return true;
  49. }
  50. public function getAbsolutePath($file, $currentPath = null)
  51. {
  52. return parent::getAbsolutePath($file, $currentPath);
  53. }
  54. }