Mock MessageComponent common access

Updated class to match the WAMP component
This commit is contained in:
Chris Boden 2012-04-29 12:38:37 -04:00
parent 6be16bea4a
commit 47e7059ed6
2 changed files with 9 additions and 22 deletions

View File

@ -41,7 +41,7 @@ class IOServerComponentTest extends \PHPUnit_Framework_TestCase {
$master = $this->getMasterConnection(); $master = $this->getMasterConnection();
$this->_server->onOpen($master); $this->_server->onOpen($master);
$clone = $this->_decorated->_conn_open; $clone = $this->_decorated->last['onOpen'][0];
$this->assertEquals($master->resourceId + 1, $clone->resourceId); $this->assertEquals($master->resourceId + 1, $clone->resourceId);
} }
@ -54,12 +54,12 @@ class IOServerComponentTest extends \PHPUnit_Framework_TestCase {
// that way can mimic the TCP fragmentation/buffer situation // that way can mimic the TCP fragmentation/buffer situation
$this->_server->onOpen($master); $this->_server->onOpen($master);
$clone = $this->_decorated->_conn_open; $clone = $this->_decorated->last['onOpen'][0];
// $this->_server->run($this->_catalyst); // $this->_server->run($this->_catalyst);
$msg = 'Hello World!'; $msg = 'Hello World!';
$this->_server->onMessage($clone, $msg); $this->_server->onMessage($clone, $msg);
$this->assertEquals($msg, $this->_decorated->_msg_recv); $this->assertEquals($msg, $this->_decorated->last['onMessage'][1]);
} }
} }

View File

@ -5,38 +5,25 @@ use Ratchet\Tests\Mock\Socket as MockSocket;
use Ratchet\Resource\ConnectionInterface; use Ratchet\Resource\ConnectionInterface;
class Component implements MessageComponentInterface { class Component implements MessageComponentInterface {
public $_app; public $last = array();
public $_conn_open;
public $_conn_recv;
public $_msg_recv;
public $_conn_close;
public $_conn_error;
public $_excep_error;
public function __construct(ComponentInterface $app = null) { public function __construct(ComponentInterface $app = null) {
// probably should make this null app $this->last[__FUNCTION__] = func_get_args();
$this->_app = $app;
} }
public function onOpen(ConnectionInterface $conn) { public function onOpen(ConnectionInterface $conn) {
$this->_conn_open = $conn; $this->last[__FUNCTION__] = func_get_args();
} }
public function onMessage(ConnectionInterface $from, $msg) { public function onMessage(ConnectionInterface $from, $msg) {
$this->_conn_recv = $from; $this->last[__FUNCTION__] = func_get_args();
$this->_msg_recv = $msg;
} }
public function onClose(ConnectionInterface $conn) { public function onClose(ConnectionInterface $conn) {
$this->_conn_close = $conn; $this->last[__FUNCTION__] = func_get_args();
} }
public function onError(ConnectionInterface $conn, \Exception $e) { public function onError(ConnectionInterface $conn, \Exception $e) {
$this->_conn_error = $conn; $this->last[__FUNCTION__] = func_get_args();
$this->_excep_error = $e;
} }
} }