Cover use of file_get_contents with a directory

This commit is contained in:
adlawson 2014-09-06 14:43:43 +01:00
parent b8d8ddf714
commit e3f60f663e
3 changed files with 19 additions and 0 deletions

View File

@ -78,6 +78,8 @@ class FileHandle extends AbstractHandle
{ {
if (!$this->node) { if (!$this->node) {
throw new UnopenedHandleException($this, $this->url); throw new UnopenedHandleException($this, $this->url);
} elseif (!$this->node instanceof FileInterface) {
return '';
} }
if (null !== $length) { if (null !== $length) {

View File

@ -11,6 +11,11 @@ class FileGetContentsAcceptanceTest extends AcceptanceTestCase
] ]
]; ];
public function testGetDirectory()
{
$this->assertEquals('', file_get_contents("$this->scheme://foo"));
}
public function testGetFile() public function testGetFile()
{ {
$this->assertEquals($this->tree['foo']['bar'], file_get_contents("$this->scheme://foo/bar")); $this->assertEquals($this->tree['foo']['bar'], file_get_contents("$this->scheme://foo/bar"));

View File

@ -219,6 +219,18 @@ class FileHandleTest extends UnitTestCase
$this->assertEquals($expected, $handle->read($offset, $length)); $this->assertEquals($expected, $handle->read($offset, $length));
} }
public function testReadNonFile()
{
$handle = new FileHandle($this->fs, 'foo://bar');
$file = Mockery::mock('Vfs\Node\NodeInterface');
$this->fs->shouldReceive('get')->once()->with('/bar')->andReturn($file);
$handle->open();
$this->assertEquals('', $handle->read(0, PHP_INT_MAX));
}
public function testReadThrowsWithoutOpening() public function testReadThrowsWithoutOpening()
{ {
$handle = new FileHandle($this->fs, 'foo://bar'); $handle = new FileHandle($this->fs, 'foo://bar');