From 30956c3c0f89111015633f036d8e116966f5289e Mon Sep 17 00:00:00 2001 From: l0gicgate Date: Fri, 3 May 2019 13:28:34 -0600 Subject: [PATCH] add test coverage for Stream::getMetadata --- src/Stream.php | 2 +- tests/StreamTest.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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');