diff --git a/src/Stream.php b/src/Stream.php index f865418..b51b589 100644 --- a/src/Stream.php +++ b/src/Stream.php @@ -83,7 +83,7 @@ public function __construct($stream) public function getMetadata($key = null) { if (!$this->stream) { - return $this->meta; + return null; } $this->meta = stream_get_meta_data($this->stream); diff --git a/tests/StreamTest.php b/tests/StreamTest.php index eaf325f..c548f85 100644 --- a/tests/StreamTest.php +++ b/tests/StreamTest.php @@ -155,6 +155,15 @@ public function testAttachAgain() $attachMethod->invoke($stream, $this->pipeFh); } + public function testGetMetaDataReturnsNullIfStreamIsDetached() + { + $resource = fopen('php://temp', 'rw+'); + $stream = new Stream($resource); + $stream->detach(); + + $this->assertNull($stream->getMetadata()); + } + private function openPipeStream() { $this->pipeFh = popen('echo 12', 'r');