From 7c44b5a2f29bb2bec5d96de202f1906594404a2a Mon Sep 17 00:00:00 2001 From: pine3ree Date: Mon, 5 Feb 2018 19:13:13 +0100 Subject: [PATCH] check fstat result --- src/Stream.php | 6 +++++- test/StreamTest.php | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Stream.php b/src/Stream.php index 8b597f97..af84d9b9 100644 --- a/src/Stream.php +++ b/src/Stream.php @@ -103,7 +103,11 @@ public function getSize() } $stats = fstat($this->resource); - return $stats['size']; + if ($stats !== false) { + return $stats['size']; + } + + return null; } /** diff --git a/test/StreamTest.php b/test/StreamTest.php index baeb3b1e..cc4166e0 100644 --- a/test/StreamTest.php +++ b/test/StreamTest.php @@ -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()); + } }