Skip to content

Commit

Permalink
Merge pull request #133 from Nekland/feature/retrieve-loop-from-conne…
Browse files Browse the repository at this point in the history
…ction

Add getter for event loop
  • Loading branch information
Nek- authored Feb 11, 2018
2 parents fa033c9 + a169756 commit 2533f9b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/Core/AbstractConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ public function close()
$this->messageProcessor->close($this->stream);
}

/**
* @return LoopInterface
*/
public function getLoop(): LoopInterface
{
return $this->loop;
}

/**
* @param string|Frame $frame
* @param int $opCode
Expand Down
17 changes: 16 additions & 1 deletion tests/Woketo/Client/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Nekland\Woketo\Rfc6455\MessageProcessor;
use Prophecy\Argument;
use React\EventLoop\LoopInterface;
use React\EventLoop\StreamSelectLoop;
use React\Promise\Promise;
use React\Socket\ConnectionInterface;

Expand Down Expand Up @@ -62,11 +63,25 @@ public function testItSendsMessagesWithMessageProcessor()

$messageProcessor->write('hello', $socket, Argument::any())->shouldBeCalled();


$promise = new Promise(function (callable $resolve, callable $reject) use ($socket) {
$resolve($socket->reveal());
});
$connection = new Connection(new Url('ws://localhost:9000'), $promise, $messageProcessor->reveal(), $messageHandler->reveal(), $loop->reveal());
$connection->write('hello');
}

public function testItGivesTheLoopBack()
{
$socket = $this->prophesize(ConnectionInterface::class);
$messageProcessor = $this->prophesize(MessageProcessor::class);
$messageHandler = $this->prophesize(MessageHandlerInterface::class);
$promise = new Promise(function (callable $resolve, callable $reject) use ($socket) {
$resolve($socket->reveal());
});

$loop = new StreamSelectLoop();
$connection = new Connection (new Url('ws://localhost:9000'), $promise, $messageProcessor->reveal(), $messageHandler->reveal(), $loop);

$this->assertSame($loop, $connection->getLoop());
}
}

0 comments on commit 2533f9b

Please sign in to comment.