[Config] Allow schemed path in FileResource

This commit is contained in:
Nicolas Grekas 2016-05-20 13:48:17 +02:00
parent d794f2f267
commit c73f34d2bc
2 changed files with 11 additions and 1 deletions

View File

@ -36,6 +36,10 @@ class FileResource implements SelfCheckingResourceInterface, \Serializable
{
$this->resource = realpath($resource);
if (false === $this->resource && file_exists($resource)) {
$this->resource = $resource;
}
if (false === $this->resource) {
throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $resource));
}

View File

@ -21,7 +21,7 @@ class FileResourceTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->file = realpath(sys_get_temp_dir()).'/tmp.xml';
$this->file = sys_get_temp_dir().'/tmp.xml';
$this->time = time();
touch($this->file, $this->time);
$this->resource = new FileResource($this->file);
@ -41,6 +41,12 @@ class FileResourceTest extends \PHPUnit_Framework_TestCase
$this->assertSame(realpath($this->file), $this->resource->getResource(), '->getResource() returns the path to the resource');
}
public function testGetResourceWithScheme()
{
$resource = new FileResource('file://'.$this->file);
$this->assertSame('file://'.$this->file, $resource->getResource(), '->getResource() returns the path to the schemed resource');
}
public function testToString()
{
$this->assertSame(realpath($this->file), (string) $this->resource);