This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/tests/Symfony/Tests/Component/Routing/Loader/FileLoaderTest.php
Jeremy Mikola c8c9fba7d9 [Routing] Add optional "type" param for loader hinting when resource strings are ambiguous
Currently, ambiguities only arise for PHP files, as PhpFileLoader and AnnotationFileLoader would both claim support.  Future conflicts may occur if the XML, YAML, or PHP loaders were to receive Directory and Glob loaders (as annotations have).

Since the "type" parameter is optional, loader resolution will default to awarding resolution to the first loader to claim support.  A previous hack in PhpFileLoader to avoid an AnnotationFileLoader conflict was removed, so that should be the only lost backwards compatibility with this patch.  Unit tests were also created for the various loader classes, although only the supports() method is being tested.

This implementation was proposed on the symfony-dev mailing list in response to Fabien's RFC for custom loader notation: http://groups.google.com/group/symfony-devs/browse_thread/thread/3104c1a9e45799d2/20fbe393c1afe088
2010-12-10 09:48:10 +01:00

71 lines
2.9 KiB
PHP

<?php
/*
* This file is part of the Symfony package.
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Tests\Component\Routing\Loader;
use Symfony\Component\Routing\Loader\FileLoader;
class FileLoaderTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers Symfony\Component\Routing\Loader\FileLoader::__construct
*/
public function testConstructor()
{
$loader = new ProjectLoader(__DIR__);
$this->assertEquals(array(__DIR__), $loader->paths, '__construct() takes a path as its second argument');
$loader = new ProjectLoader(array(__DIR__, __DIR__));
$this->assertEquals(array(__DIR__, __DIR__), $loader->paths, '__construct() takes an array of paths as its second argument');
}
/**
* @covers Symfony\Component\Routing\Loader\FileLoader::GetAbsolutePath
* @covers Symfony\Component\Routing\Loader\FileLoader::isAbsolutePath
*/
public function testGetAbsolutePath()
{
$loader = new ProjectLoader(array(__DIR__.'/../Fixtures'));
$this->assertEquals('/foo.xml', $loader->getAbsolutePath('/foo.xml'), '->getAbsolutePath() return the path unmodified if it is already an absolute path');
$this->assertEquals('c:\\\\foo.xml', $loader->getAbsolutePath('c:\\\\foo.xml'), '->getAbsolutePath() return the path unmodified if it is already an absolute path');
$this->assertEquals('c:/foo.xml', $loader->getAbsolutePath('c:/foo.xml'), '->getAbsolutePath() return the path unmodified if it is already an absolute path');
$this->assertEquals('\\server\\foo.xml', $loader->getAbsolutePath('\\server\\foo.xml'), '->getAbsolutePath() return the path unmodified if it is already an absolute path');
$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');
$this->assertEquals(__DIR__.'/../Fixtures'.DIRECTORY_SEPARATOR.'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');
$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');
}
}
class ProjectLoader extends FileLoader
{
public $paths;
public function load($resource, $type = null)
{
}
public function supports($resource, $type = null)
{
return true;
}
public function getType()
{
}
public function getAbsolutePath($file, $currentPath = null)
{
return parent::getAbsolutePath($file, $currentPath);
}
}