diff --git a/src/ControlCodeParser.php b/src/ControlCodeParser.php index eb1a592..a1bb90f 100644 --- a/src/ControlCodeParser.php +++ b/src/ControlCodeParser.php @@ -84,6 +84,7 @@ public function close() } $this->closed = true; + $this->buffer = ''; $this->input->close(); diff --git a/tests/ControlCodeParserTest.php b/tests/ControlCodeParserTest.php index 7b2cda3..ec2b8d7 100644 --- a/tests/ControlCodeParserTest.php +++ b/tests/ControlCodeParserTest.php @@ -122,6 +122,18 @@ public function testEmitsDataInTwoChunkWithC0InBetweenWhileAddingDuringDataEvent $this->input->emit('data', array("hello\nworld")); } + public function testEmitsDataOnlyFirstChunkOfMultipleWhenClosingDuringFirstDataEvent() + { + // first data event is everything before control code + $first = $this->expectCallableOnceWith('hello'); + $this->parser->on('data', $first); + + // close the input stream on the first data event => no more data events + $this->parser->once('data', array($this->input, 'close')); + + $this->input->emit('data', array("hello\nworld")); + } + public function testEmitsC0AndData() { $this->parser->on('data', $this->expectCallableOnceWith("hello world"));