FileLoaderTest.php 2.3 KB

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