#7531: [HttpKernel][Config] FileLocator adds NULL as global resource path

This commit is contained in:
Roland Franssen 2013-04-01 13:19:43 +02:00 committed by Fabien Potencier
parent 95927c772c
commit a3826ab4f4
2 changed files with 67 additions and 4 deletions

10
src/Symfony/Component/HttpKernel/Config/FileLocator.php Normal file → Executable file
View File

@ -28,14 +28,16 @@ class FileLocator extends BaseFileLocator
* Constructor.
*
* @param KernelInterface $kernel A KernelInterface instance
* @param string $path The path the global resource directory
* @param string|array $paths A path or an array of paths where to look for resources
* @param null|string $path The path the global resource directory
* @param array $paths An array of paths where to look for resources
*/
public function __construct(KernelInterface $kernel, $path = null, array $paths = array())
{
$this->kernel = $kernel;
$this->path = $path;
$paths[] = $path;
if(null !== $path) {
$this->path = $path;
$paths[] = $path;
}
parent::__construct($paths);
}

View File

@ -0,0 +1,61 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\HttpKernel\Tests\Config;
use Symfony\Component\HttpKernel\Config\FileLocator;
use Symfony\Component\HttpKernel\KernelInterface;
class FileLocatorTest extends \PHPUnit_Framework_TestCase
{
/** @var KernelInterface */
private $kernel;
public function setUp()
{
$this->kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface');
}
public function tearDown()
{
$this->kernel = null;
}
public function testLocate()
{
$this->kernel
->expects($this->atLeastOnce())
->method('locateResource')
->with('@BundleName/some/path', null, true)
->will($this->returnValue('/bundle-name/some/path'));
$locator = new FileLocator($this->kernel);
$this->assertEquals('/bundle-name/some/path', $locator->locate('@BundleName/some/path'));
$this->kernel
->expects($this->never())
->method('locateResource');
$this->setExpectedException('LogicException');
$locator->locate('/some/path');
}
public function testLocateWithGlobalResourcePath()
{
$this->kernel
->expects($this->atLeastOnce())
->method('locateResource')
->with('@BundleName/some/path', '/global/resource/path', false);
$locator = new FileLocator($this->kernel, '/global/resource/path');
$locator->locate('@BundleName/some/path', null, false);
}
}