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/DependencyInjection/Loader/FileLoaderTest.php

68 lines
3.0 KiB
PHP
Raw Normal View History

<?php
/*
2010-04-25 16:06:54 +01:00
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
2010-04-07 02:07:59 +01:00
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Tests\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\FileLoader;
2010-06-27 17:28:29 +01:00
class FileLoaderTest extends \PHPUnit_Framework_TestCase
{
2010-06-27 17:28:29 +01:00
/**
* @covers Symfony\Component\DependencyInjection\Loader\FileLoader::__construct
2010-06-27 17:28:29 +01:00
*/
public function testConstructor()
{
$loader = new ProjectLoader(new ContainerBuilder(), __DIR__);
$this->assertEquals(array(__DIR__), $loader->paths, '__construct() takes a path as its second argument');
$loader = new ProjectLoader(new ContainerBuilder(), array(__DIR__, __DIR__));
$this->assertEquals(array(__DIR__, __DIR__), $loader->paths, '__construct() takes an array of paths as its second argument');
}
2010-06-27 17:28:29 +01:00
/**
* @covers Symfony\Component\DependencyInjection\Loader\FileLoader::GetAbsolutePath
2010-06-27 17:28:29 +01:00
*/
public function testGetAbsolutePath()
{
$loader = new ProjectLoader(new ContainerBuilder(), array(__DIR__.'/../Fixtures/containers'));
$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');
2010-06-28 08:31:54 +01:00
$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');
$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');
}
}
class ProjectLoader extends FileLoader
{
public $paths;
public function load($resource, ContainerBuilder $container = null)
{
}
public function supports($resource)
{
return true;
}
public function getAbsolutePath($file, $currentPath = null)
{
return parent::getAbsolutePath($file, $currentPath);
}
}