Skip to content

Commit 1318841

Browse files
committed
Fix CloseProtectionTests
1 parent eb13180 commit 1318841

File tree

1 file changed

+36
-18
lines changed

1 file changed

+36
-18
lines changed

tests/CloseProtectionStreamTest.php

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class CloseProtectionStreamTest extends TestCase
99
{
10-
public function testCloseEventDoesntCloseInputStream()
10+
public function testClosePausesTheInputStreamInsteadOfClosing()
1111
{
1212
$input = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->getMock();
1313
$input->expects($this->never())->method('close');
@@ -31,11 +31,10 @@ public function testHandleError()
3131

3232
$protection = new CloseProtectionStream($input);
3333
$protection->on('error', $this->expectCallableOnce());
34-
$protection->on('close', $this->expectCallableOnce());
3534

3635
$input->emit('error', array(new \RuntimeException()));
3736

38-
$this->assertFalse($protection->isReadable());
37+
$this->assertTrue($protection->isReadable());
3938
$this->assertTrue($input->isReadable());
4039
}
4140

@@ -78,25 +77,11 @@ public function testHandleClose()
7877
$protection->on('close', $this->expectCallableOnce());
7978

8079
$input->close();
81-
$input->emit('end', array());
8280

8381
$this->assertFalse($protection->isReadable());
8482
$this->assertFalse($input->isReadable());
8583
}
8684

87-
public function testSendEndViaPipe()
88-
{
89-
$input = new ReadableStream();
90-
91-
$protection = new CloseProtectionStream($input);
92-
$protection->on('close', $this->expectCallableOnce());
93-
94-
$input->close();
95-
$input->emit('end', array());
96-
97-
$this->assertFalse($protection->isReadable());
98-
}
99-
10085
public function testStopEmittingDataAfterClose()
10186
{
10287
$input = new ReadableStream();
@@ -149,14 +134,47 @@ public function testEndWontBeEmittedAfterClose()
149134

150135
public function closeEventPausesInputStream()
151136
{
152-
$input = $this->getMock('React\Stream\ReadableStreamInterface');
137+
$input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
138+
$input->expects($this->once())->method('pause');
139+
140+
$protection = new CloseProtectionStream($input);
141+
142+
$protection->on('data', $this->expectCallableNever());
143+
$protection->on('close', $this->expectCallableOnce());
144+
145+
$protection->close();
146+
}
147+
148+
public function testPauseAfterCloseWontBeEmittedFurther()
149+
{
150+
$input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
153151
$input->expects($this->once())->method('pause');
154152

155153
$protection = new CloseProtectionStream($input);
154+
$protection->on('data', $this->expectCallableNever());
155+
156+
$protection->on('close', $this->expectCallableOnce());
157+
158+
$protection->close();
159+
$protection->pause();
160+
161+
$input->emit('data', array('hello'));
162+
}
163+
164+
public function testResumeAfterCloseWontBeEmittedFurther()
165+
{
166+
$input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
167+
$input->expects($this->once())->method('pause');
168+
$input->expects($this->never())->method('resume');
169+
156170
$protection = new CloseProtectionStream($input);
157171
$protection->on('data', $this->expectCallableNever());
172+
158173
$protection->on('close', $this->expectCallableOnce());
159174

160175
$protection->close();
176+
$protection->resume();
177+
178+
$input->emit('data', array('hello'));
161179
}
162180
}

0 commit comments

Comments
 (0)