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

Commit 7c44b5a

Browse files
committed
check fstat result
1 parent b57ec28 commit 7c44b5a

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/Stream.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ public function getSize()
103103
}
104104

105105
$stats = fstat($this->resource);
106-
return $stats['size'];
106+
if ($stats !== false) {
107+
return $stats['size'];
108+
}
109+
110+
return null;
107111
}
108112

109113
/**

test/StreamTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,4 +632,25 @@ public function testCanReadContentFromNotSeekableResource()
632632

633633
$this->assertSame('FOO BAR', $stream->__toString());
634634
}
635+
636+
/**
637+
* @group 42
638+
*/
639+
public function testSizeReportsNullForPhpInputStreams()
640+
{
641+
$resource = fopen('php://input', 'r');
642+
$stream = new Stream($resource);
643+
$this->assertNull($stream->getSize());
644+
}
645+
646+
/**
647+
* @group 42
648+
*/
649+
public function testSizeReportsNullForRemoteResources()
650+
{
651+
$resource_url = 'http://www.php.net/images/logos/php-logo.png';
652+
$resource = fopen($resource_url, 'r');
653+
$stream = new Stream($resource);
654+
$this->assertNull($stream->getSize());
655+
}
635656
}

0 commit comments

Comments
 (0)