FileLoaderTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. require_once __DIR__.'/../../../bootstrap.php';
  11. use Symfony\Components\DependencyInjection\Builder;
  12. use Symfony\Components\DependencyInjection\Loader\FileLoader;
  13. class XmlDumperTest extends \PHPUnit_Framework_TestCase
  14. {
  15. public function testConstructor()
  16. {
  17. $loader = new ProjectLoader(__DIR__);
  18. $this->assertEquals($loader->paths, array(__DIR__), '__construct() takes a path as its second argument');
  19. $loader = new ProjectLoader(array(__DIR__, __DIR__));
  20. $this->assertEquals($loader->paths, array(__DIR__, __DIR__), '__construct() takes an array of paths as its second argument');
  21. }
  22. public function testGetAbsolutePath()
  23. {
  24. $loader = new ProjectLoader(array(__DIR__.'/../../../../../fixtures/Symfony/Components/DependencyInjection/containers'));
  25. $this->assertEquals($loader->getAbsolutePath('/foo.xml'), '/foo.xml', '->getAbsolutePath() return the path unmodified if it is already an absolute path');
  26. $this->assertEquals($loader->getAbsolutePath('c:\\\\foo.xml'), 'c:\\\\foo.xml', '->getAbsolutePath() return the path unmodified if it is already an absolute path');
  27. $this->assertEquals($loader->getAbsolutePath('c:/foo.xml'), 'c:/foo.xml', '->getAbsolutePath() return the path unmodified if it is already an absolute path');
  28. $this->assertEquals($loader->getAbsolutePath('\\server\\foo.xml'), '\\server\\foo.xml', '->getAbsolutePath() return the path unmodified if it is already an absolute path');
  29. $this->assertEquals($loader->getAbsolutePath('FileLoaderTest.php', __DIR__), __DIR__.'/FileLoaderTest.php', '->getAbsolutePath() returns an absolute filename if the file exists in the current path');
  30. $this->assertEquals($loader->getAbsolutePath('container10.php', __DIR__), __DIR__.'/../../../../../fixtures/Symfony/Components/DependencyInjection/containers/container10.php', '->getAbsolutePath() returns an absolute filename if the file exists in one of the paths given in the constructor');
  31. $this->assertEquals($loader->getAbsolutePath('foo.xml', __DIR__), 'foo.xml', '->getAbsolutePath() returns the path unmodified if it is unable to find it in the given paths');
  32. }
  33. }
  34. class ProjectLoader extends FileLoader
  35. {
  36. public $paths;
  37. public function load($resource)
  38. {
  39. }
  40. public function getAbsolutePath($file, $currentPath = null)
  41. {
  42. return parent::getAbsolutePath($file, $currentPath);
  43. }
  44. }