[WAMP] Work
Unit testing WAMP; 0 -> 84% coverage Fixed an Event command bug API documentation
This commit is contained in:
parent
228d0b8627
commit
9e667dfc8b
src/Ratchet/Component/WAMP
tests/Ratchet/Tests/Mock
@ -3,30 +3,76 @@ namespace Ratchet\Component\WAMP\Command\Action;
|
||||
use Ratchet\Resource\Command\Action\SendMessage;
|
||||
use Ratchet\Component\WAMP\WAMPServerComponent as WAMP;
|
||||
|
||||
/**
|
||||
* Respond to a client RPC with an error
|
||||
*/
|
||||
class CallError extends SendMessage {
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_uri;
|
||||
|
||||
protected $_desc;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_desc = '';
|
||||
|
||||
public function setError($callId, $uri, $desc) {
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_details;
|
||||
|
||||
/**
|
||||
* @param string The unique ID given by the client to respond to
|
||||
* @param string The URI given by the client ot respond to
|
||||
* @param string A developer-oriented description of the error
|
||||
* @param string|null An optional human readable detail message to send back
|
||||
* @return CallError
|
||||
*/
|
||||
public function setError($callId, $uri, $desc = '', $details = null) {
|
||||
$this->_id = $callId;
|
||||
$this->_uri = $uri;
|
||||
$this->_desc = $desc;
|
||||
|
||||
return $this->setMessage(json_encode(array(WAMP::MSG_CALL_ERROR, $callId, $uri, $desc)));
|
||||
$data = array(WAMP::MSG_CALL_ERROR, $callId, $uri, $desc);
|
||||
|
||||
if (null !== $details) {
|
||||
$data[] = $details;
|
||||
}
|
||||
|
||||
return $this->setMessage(json_encode($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getId() {
|
||||
return $this->_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getUri() {
|
||||
return $this->_uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription() {
|
||||
return $this->_desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getDetails() {
|
||||
return $this->_details;
|
||||
}
|
||||
}
|
@ -4,12 +4,24 @@ use Ratchet\Resource\Command\Action\SendMessage;
|
||||
use Ratchet\Component\WAMP\WAMPServerComponent as WAMP;
|
||||
|
||||
/**
|
||||
* Respond to a client RPC
|
||||
*/
|
||||
class CallResult extends SendMessage {
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_id;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $_data;
|
||||
|
||||
/**
|
||||
* @param string The unique ID given by the client to respond to
|
||||
* @param array An array of data to return to the client
|
||||
* @return CallResult
|
||||
*/
|
||||
public function setResult($callId, array $data = array()) {
|
||||
$this->_id = $callId;
|
||||
$this->_data = $data;
|
||||
@ -17,10 +29,16 @@ class CallResult extends SendMessage {
|
||||
return $this->setMessage(json_encode(array(WAMP::MSG_CALL_RESULT, $callId, $data)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getId() {
|
||||
return $this->_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|null
|
||||
*/
|
||||
public function getData() {
|
||||
return $this->_data;
|
||||
}
|
||||
|
@ -14,6 +14,6 @@ class Event extends SendMessage {
|
||||
* @return Event
|
||||
*/
|
||||
public function setEvent($uri, $msg) {
|
||||
return $this->setMessage(json_encode(array(WAMP::MSG_EVENT, $uri, (string)$msg)));
|
||||
return $this->setMessage(json_encode(array(WAMP::MSG_EVENT, $uri, $msg)));
|
||||
}
|
||||
}
|
@ -84,7 +84,6 @@ class WAMPServerComponent implements WebSocketComponentInterface {
|
||||
$conn->WAMP = new \StdClass;
|
||||
$conn->WAMP->sessionId = uniqid();
|
||||
$conn->WAMP->prefixes = array();
|
||||
$conn->WAMP->subscriptions = array();
|
||||
|
||||
$wamp = $this;
|
||||
$conn->WAMP->addPrefix = function($curie, $uri) use ($wamp, $conn) {
|
||||
|
36
tests/Ratchet/Tests/Mock/WAMPComponent.php
Normal file
36
tests/Ratchet/Tests/Mock/WAMPComponent.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace Ratchet\Tests\Mock;
|
||||
use Ratchet\Component\WAMP\WAMPServerComponentInterface;
|
||||
use Ratchet\Resource\ConnectionInterface;
|
||||
|
||||
class WAMPComponent implements WAMPServerComponentInterface {
|
||||
public $last = array();
|
||||
|
||||
public function onCall(ConnectionInterface $conn, $id, $procURI, array $params) {
|
||||
$this->last[__FUNCTION__] = func_get_args();
|
||||
}
|
||||
|
||||
public function onSubscribe(ConnectionInterface $conn, $uri) {
|
||||
$this->last[__FUNCTION__] = func_get_args();
|
||||
}
|
||||
|
||||
public function onUnSubscribe(ConnectionInterface $conn, $uri) {
|
||||
$this->last[__FUNCTION__] = func_get_args();
|
||||
}
|
||||
|
||||
public function onPublish(ConnectionInterface $conn, $uri, $event) {
|
||||
$this->last[__FUNCTION__] = func_get_args();
|
||||
}
|
||||
|
||||
public function onOpen(ConnectionInterface $conn) {
|
||||
$this->last[__FUNCTION__] = func_get_args();
|
||||
}
|
||||
|
||||
public function onClose(ConnectionInterface $conn) {
|
||||
$this->last[__FUNCTION__] = func_get_args();
|
||||
}
|
||||
|
||||
public function onError(ConnectionInterface $conn, \Exception $e) {
|
||||
$this->last[__FUNCTION__] = func_get_args();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user