From a7a61847c152355ad24e5400146830aa456a6cfc Mon Sep 17 00:00:00 2001 From: Beau Collins Date: Tue, 18 Dec 2012 16:17:34 -0800 Subject: [PATCH] React\Http\Response emits 'end' event when stream is ended --- src/React/Http/Response.php | 2 +- tests/React/Tests/Http/ResponseTest.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/React/Http/Response.php b/src/React/Http/Response.php index 0bfd28e1..80d0b4ff 100644 --- a/src/React/Http/Response.php +++ b/src/React/Http/Response.php @@ -98,7 +98,7 @@ public function end($data = null) $this->conn->write("0\r\n\r\n"); } - $this->emit('close'); + $this->emit('end'); $this->removeAllListeners(); $this->conn->end(); } diff --git a/tests/React/Tests/Http/ResponseTest.php b/tests/React/Tests/Http/ResponseTest.php index d035e600..4f52df86 100644 --- a/tests/React/Tests/Http/ResponseTest.php +++ b/tests/React/Tests/Http/ResponseTest.php @@ -71,6 +71,19 @@ public function testResponseBodyShouldBeChunkedCorrectly() $response->write("World\n"); $response->end(); } + + public function testResponseShouldEmitEndOnStreamEnd(){ + $conn = $this->getMock('React\Socket\ConnectionInterface'); + $response = new Response( $conn ); + $ended = false; + $response->on( 'end', function() use (&$ended){ + $ended = true; + }); + $response->end(); + + $this->assertTrue( $ended, "Response did not emit 'end'" ); + + } /** @test */ public function writeContinueShouldSendContinueLineBeforeRealHeaders()