Skip to content

Commit 5835c45

Browse files
committed
Emit end and close event on connection closed
1 parent 487f257 commit 5835c45

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/React/MySQL/Connection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ public function close($callback = null)
156156
$this->_doCommand(new QuitCommand($this))
157157
->on('success', function () use ($callback) {
158158
$this->state = self::STATE_CLOSED;
159+
$this->emit('end', [$this]);
160+
$this->emit('close', [$this]);
159161
if ($callback) {
160162
$callback($this);
161163
}

tests/React/Tests/ConnectionTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,21 @@ public function testConnectWithInvalidPass()
2727

2828
public function testConnectWithValidPass()
2929
{
30+
$this->expectOutputString('endclose');
31+
3032
$loop = \React\EventLoop\Factory::create();
3133
$conn = new Connection($loop, $this->connectOptions );
3234

35+
$conn->on('end', function ($conn){
36+
$this->assertInstanceOf('React\MySQL\Connection', $conn);
37+
echo 'end';
38+
});
39+
40+
$conn->on('close', function ($conn){
41+
$this->assertInstanceOf('React\MySQL\Connection', $conn);
42+
echo 'close';
43+
});
44+
3345
$conn->connect(function ($err, $conn) use ($loop) {
3446
$this->assertEquals(null, $err);
3547
$this->assertInstanceOf('React\MySQL\Connection', $conn);

0 commit comments

Comments
 (0)