From 9524fac13e486d9823d439544423bc64f3162322 Mon Sep 17 00:00:00 2001 From: nawarian Date: Tue, 14 Feb 2017 23:02:52 -0200 Subject: [PATCH 1/2] Test: Covering React\Stream\isReadable|isWritable methods --- tests/StreamTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/StreamTest.php b/tests/StreamTest.php index 3ac2d79..a3658e8 100644 --- a/tests/StreamTest.php +++ b/tests/StreamTest.php @@ -149,6 +149,8 @@ public function testWrite() /** * @covers React\Stream\Stream::end + * @covers React\Stream\Stream::isReadable + * @covers React\Stream\Stream::isWritable */ public function testEnd() { @@ -159,6 +161,8 @@ public function testEnd() $conn->end(); $this->assertFalse(is_resource($stream)); + $this->assertFalse($conn->isReadable()); + $this->assertFalse($conn->isWritable()); } public function testBufferEventsShouldBubbleUp() From 2c5ad314a1f19f5d0c6fd39d799cfc623b3d0db8 Mon Sep 17 00:00:00 2001 From: nawarian Date: Tue, 14 Feb 2017 23:18:24 -0200 Subject: [PATCH 2/2] Test: ended streams should not affect their resources --- tests/StreamTest.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/StreamTest.php b/tests/StreamTest.php index a3658e8..9f3a3af 100644 --- a/tests/StreamTest.php +++ b/tests/StreamTest.php @@ -165,6 +165,25 @@ public function testEnd() $this->assertFalse($conn->isWritable()); } + public function testEndedStreamsShouldNotWrite() + { + $file = tempnam(sys_get_temp_dir(), 'reactphptest_'); + $stream = fopen($file, 'r+'); + $loop = $this->createWriteableLoopMock(); + + $conn = new Stream($stream, $loop); + $conn->write("foo\n"); + $conn->end(); + + $res = $conn->write("bar\n"); + $stream = fopen($file, 'r'); + + $this->assertSame("foo\n", fgets($stream)); + $this->assertNull($res); + + unlink($file); + } + public function testBufferEventsShouldBubbleUp() { $stream = fopen('php://temp', 'r+');