Skip to content

Commit 018c48c

Browse files
committed
Emit error on unexpected end of LengtLimitedStream
1 parent fa7ccf7 commit 018c48c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/LengthLimitedStream.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ public function handleError(\Exception $e)
9494
public function handleEnd()
9595
{
9696
if (!$this->closed) {
97-
$this->emit('end');
98-
$this->close();
97+
$this->handleError(new \Exception('Unexpected end event'));
9998
}
10099
}
101100

tests/LengthLimitedStreamTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,16 @@ public function testOutputStreamCanCloseInputStream()
105105

106106
$this->assertFalse($input->isReadable());
107107
}
108+
109+
public function testHandleUnexpectedEnd()
110+
{
111+
$stream = new LengthLimitedStream($this->input, 5);
112+
113+
$stream->on('data', $this->expectCallableNever());
114+
$stream->on('close', $this->expectCallableOnce());
115+
$stream->on('end', $this->expectCallableNever());
116+
$stream->on('error', $this->expectCallableOnce());
117+
118+
$this->input->emit('end');
119+
}
108120
}

0 commit comments

Comments
 (0)