FileLoaderTest.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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\Components\DependencyInjection\Loader;
  10. use Symfony\Components\DependencyInjection\Builder;
  11. use Symfony\Components\DependencyInjection\BuilderConfiguration;
  12. use Symfony\Components\DependencyInjection\Loader\FileLoader;
  13. class FileLoaderTest extends \PHPUnit_Framework_TestCase
  14. {
  15. /**
  16. * @covers Symfony\Components\DependencyInjection\Loader\FileLoader::__construct
  17. */
  18. public function testConstructor()
  19. {
  20. $loader = new ProjectLoader(__DIR__);
  21. $this->assertEquals(array(__DIR__), $loader->paths, '__construct() takes a path as its second argument');
  22. $loader = new ProjectLoader(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\Components\DependencyInjection\Loader\FileLoader::GetAbsolutePath
  27. */
  28. public function testGetAbsolutePath()
  29. {
  30. $loader = new ProjectLoader(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, $main = true, BuilderConfiguration $configuration = null)
  44. {
  45. }
  46. public function getAbsolutePath($file, $currentPath = null)
  47. {
  48. return parent::getAbsolutePath($file, $currentPath);
  49. }
  50. }