Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
check fstat result
Browse files Browse the repository at this point in the history
  • Loading branch information
pine3ree committed Feb 5, 2018
1 parent b57ec28 commit 7c44b5a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ public function getSize()
}

$stats = fstat($this->resource);
return $stats['size'];
if ($stats !== false) {
return $stats['size'];
}

return null;
}

/**
Expand Down
21 changes: 21 additions & 0 deletions test/StreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -632,4 +632,25 @@ public function testCanReadContentFromNotSeekableResource()

$this->assertSame('FOO BAR', $stream->__toString());
}

/**
* @group 42
*/
public function testSizeReportsNullForPhpInputStreams()
{
$resource = fopen('php://input', 'r');
$stream = new Stream($resource);
$this->assertNull($stream->getSize());
}

/**
* @group 42
*/
public function testSizeReportsNullForRemoteResources()
{
$resource_url = 'http://www.php.net/images/logos/php-logo.png';
$resource = fopen($resource_url, 'r');
$stream = new Stream($resource);
$this->assertNull($stream->getSize());
}
}

0 comments on commit 7c44b5a

Please sign in to comment.