Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove event listeners from CompositeStream once closed and remove remove undocumented left-over close event argument #116

Merged
merged 2 commits into from
Oct 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/CompositeStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -77,5 +77,6 @@ public function close()
$this->writable->close();

$this->emit('close');
$this->removeAllListeners();
}
}
8 changes: 1 addition & 7 deletions src/WritableResourceStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
19 changes: 19 additions & 0 deletions tests/CompositeStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down