Skip to content

Commit 8ab6c52

Browse files
ro0NLfabpot
authored andcommitted
#7531: [HttpKernel][Config] FileLocator adds NULL as global resource path
1 parent 65202c1 commit 8ab6c52

File tree

2 files changed

+67
-4
lines changed

2 files changed

+67
-4
lines changed

Config/FileLocator.php

100644100755
+6-4
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ class FileLocator extends BaseFileLocator
2828
* Constructor.
2929
*
3030
* @param KernelInterface $kernel A KernelInterface instance
31-
* @param string $path The path the global resource directory
32-
* @param string|array $paths A path or an array of paths where to look for resources
31+
* @param null|string $path The path the global resource directory
32+
* @param array $paths An array of paths where to look for resources
3333
*/
3434
public function __construct(KernelInterface $kernel, $path = null, array $paths = array())
3535
{
3636
$this->kernel = $kernel;
37-
$this->path = $path;
38-
$paths[] = $path;
37+
if(null !== $path) {
38+
$this->path = $path;
39+
$paths[] = $path;
40+
}
3941

4042
parent::__construct($paths);
4143
}

Tests/Config/FileLocatorTest.php

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpKernel\Tests\Config;
13+
14+
use Symfony\Component\HttpKernel\Config\FileLocator;
15+
use Symfony\Component\HttpKernel\KernelInterface;
16+
17+
class FileLocatorTest extends \PHPUnit_Framework_TestCase
18+
{
19+
20+
/** @var KernelInterface */
21+
private $kernel;
22+
23+
public function setUp()
24+
{
25+
$this->kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface');
26+
}
27+
28+
public function tearDown()
29+
{
30+
$this->kernel = null;
31+
}
32+
33+
public function testLocate()
34+
{
35+
$this->kernel
36+
->expects($this->atLeastOnce())
37+
->method('locateResource')
38+
->with('@BundleName/some/path', null, true)
39+
->will($this->returnValue('/bundle-name/some/path'));
40+
$locator = new FileLocator($this->kernel);
41+
$this->assertEquals('/bundle-name/some/path', $locator->locate('@BundleName/some/path'));
42+
43+
$this->kernel
44+
->expects($this->never())
45+
->method('locateResource');
46+
$this->setExpectedException('LogicException');
47+
$locator->locate('/some/path');
48+
}
49+
50+
public function testLocateWithGlobalResourcePath()
51+
{
52+
$this->kernel
53+
->expects($this->atLeastOnce())
54+
->method('locateResource')
55+
->with('@BundleName/some/path', '/global/resource/path', false);
56+
57+
$locator = new FileLocator($this->kernel, '/global/resource/path');
58+
$locator->locate('@BundleName/some/path', null, false);
59+
}
60+
61+
}

0 commit comments

Comments
 (0)