Skip to content

Commit

Permalink
#7531: [HttpKernel][Config] FileLocator adds NULL as global resource …
Browse files Browse the repository at this point in the history
…path
  • Loading branch information
ro0NL authored and fabpot committed Apr 7, 2013
1 parent fffa53e commit 4498964
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Symfony/Component/HttpKernel/Config/FileLocator.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
61 changes: 61 additions & 0 deletions src/Symfony/Component/HttpKernel/Tests/Config/FileLocatorTest.php
Original file line number Diff line number Diff line change
@@ -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);
}

}

0 comments on commit 4498964

Please sign in to comment.