diff --git a/src/CompositeStream.php b/src/CompositeStream.php index d9253e4..153f2a3 100644 --- a/src/CompositeStream.php +++ b/src/CompositeStream.php @@ -6,9 +6,9 @@ final class CompositeStream extends EventEmitter implements DuplexStreamInterface { - protected $readable; - protected $writable; - protected $closed = false; + private $readable; + private $writable; + private $closed = false; public function __construct(ReadableStreamInterface $readable, WritableStreamInterface $writable) { @@ -77,5 +77,6 @@ public function close() $this->writable->close(); $this->emit('close'); + $this->removeAllListeners(); } } diff --git a/src/WritableResourceStream.php b/src/WritableResourceStream.php index 8230ff9..f43f95c 100644 --- a/src/WritableResourceStream.php +++ b/src/WritableResourceStream.php @@ -92,15 +92,9 @@ public function close() $this->writable = false; $this->data = ''; - $this->emit('close', array($this)); + $this->emit('close'); $this->removeAllListeners(); - $this->handleClose(); - } - - /** @internal */ - public function handleClose() - { if (is_resource($this->stream)) { fclose($this->stream); } diff --git a/tests/CompositeStreamTest.php b/tests/CompositeStreamTest.php index 4b4b2f4..df89c3e 100644 --- a/tests/CompositeStreamTest.php +++ b/tests/CompositeStreamTest.php @@ -188,6 +188,25 @@ public function itShouldForwardCloseOnlyOnce() $writable->close(); } + /** @test */ + public function itShouldForwardCloseAndRemoveAllListeners() + { + $in = new ThroughStream(); + + $composite = new CompositeStream($in, $in); + $composite->on('close', $this->expectCallableOnce()); + + $this->assertTrue($composite->isReadable()); + $this->assertTrue($composite->isWritable()); + $this->assertCount(1, $composite->listeners('close')); + + $composite->close(); + + $this->assertFalse($composite->isReadable()); + $this->assertFalse($composite->isWritable()); + $this->assertCount(0, $composite->listeners('close')); + } + /** @test */ public function itShouldReceiveForwardedEvents() {