diff options
author | marvin-borner@live.com | 2018-04-10 21:50:16 +0200 |
---|---|---|
committer | marvin-borner@live.com | 2018-04-10 21:54:48 +0200 |
commit | fc9401f04a3aca5abb22f87ebc210de8afe11d32 (patch) | |
tree | b0b310f3581764ec3955f4e496a05137a32951c3 /assets/php/vendor/cboden/ratchet/tests/helpers | |
parent | 286d643180672f20526f3dc3bd19d7b751e2fa97 (diff) |
Initial Commit
Diffstat (limited to 'assets/php/vendor/cboden/ratchet/tests/helpers')
8 files changed, 212 insertions, 0 deletions
diff --git a/assets/php/vendor/cboden/ratchet/tests/helpers/Ratchet/AbstractMessageComponentTestCase.php b/assets/php/vendor/cboden/ratchet/tests/helpers/Ratchet/AbstractMessageComponentTestCase.php new file mode 100644 index 0000000..8c298e5 --- /dev/null +++ b/assets/php/vendor/cboden/ratchet/tests/helpers/Ratchet/AbstractMessageComponentTestCase.php @@ -0,0 +1,50 @@ +<?php +namespace Ratchet; + +abstract class AbstractMessageComponentTestCase extends \PHPUnit_Framework_TestCase { + protected $_app; + protected $_serv; + protected $_conn; + + abstract public function getConnectionClassString(); + abstract public function getDecoratorClassString(); + abstract public function getComponentClassString(); + + public function setUp() { + $this->_app = $this->getMock($this->getComponentClassString()); + $decorator = $this->getDecoratorClassString(); + $this->_serv = new $decorator($this->_app); + $this->_conn = $this->getMock('\Ratchet\ConnectionInterface'); + + $this->doOpen($this->_conn); + } + + protected function doOpen($conn) { + $this->_serv->onOpen($conn); + } + + public function isExpectedConnection() { + return new \PHPUnit_Framework_Constraint_IsInstanceOf($this->getConnectionClassString()); + } + + public function testOpen() { + $this->_app->expects($this->once())->method('onOpen')->with($this->isExpectedConnection()); + $this->doOpen($this->getMock('\Ratchet\ConnectionInterface')); + } + + public function testOnClose() { + $this->_app->expects($this->once())->method('onClose')->with($this->isExpectedConnection()); + $this->_serv->onClose($this->_conn); + } + + public function testOnError() { + $e = new \Exception('Whoops!'); + $this->_app->expects($this->once())->method('onError')->with($this->isExpectedConnection(), $e); + $this->_serv->onError($this->_conn, $e); + } + + public function passthroughMessageTest($value) { + $this->_app->expects($this->once())->method('onMessage')->with($this->isExpectedConnection(), $value); + $this->_serv->onMessage($this->_conn, $value); + } +} diff --git a/assets/php/vendor/cboden/ratchet/tests/helpers/Ratchet/Mock/Component.php b/assets/php/vendor/cboden/ratchet/tests/helpers/Ratchet/Mock/Component.php new file mode 100644 index 0000000..e152988 --- /dev/null +++ b/assets/php/vendor/cboden/ratchet/tests/helpers/Ratchet/Mock/Component.php @@ -0,0 +1,35 @@ +<?php +namespace Ratchet\Mock; +use Ratchet\MessageComponentInterface; +use Ratchet\WebSocket\WsServerInterface; +use Ratchet\ConnectionInterface; + +class Component implements MessageComponentInterface, WsServerInterface { + public $last = array(); + + public $protocols = array(); + + public function __construct(ComponentInterface $app = null) { + $this->last[__FUNCTION__] = func_get_args(); + } + + public function onOpen(ConnectionInterface $conn) { + $this->last[__FUNCTION__] = func_get_args(); + } + + public function onMessage(ConnectionInterface $from, $msg) { + $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(); + } + + public function getSubProtocols() { + return $this->protocols; + } +} diff --git a/assets/php/vendor/cboden/ratchet/tests/helpers/Ratchet/Mock/Connection.php b/assets/php/vendor/cboden/ratchet/tests/helpers/Ratchet/Mock/Connection.php new file mode 100644 index 0000000..5918296 --- /dev/null +++ b/assets/php/vendor/cboden/ratchet/tests/helpers/Ratchet/Mock/Connection.php @@ -0,0 +1,20 @@ +<?php +namespace Ratchet\Mock; +use Ratchet\ConnectionInterface; + +class Connection implements ConnectionInterface { + public $last = array( + 'send' => '' + , 'close' => false + ); + + public $remoteAddress = '127.0.0.1'; + + public function send($data) { + $this->last[__FUNCTION__] = $data; + } + + public function close() { + $this->last[__FUNCTION__] = true; + } +} diff --git a/assets/php/vendor/cboden/ratchet/tests/helpers/Ratchet/Mock/ConnectionDecorator.php b/assets/php/vendor/cboden/ratchet/tests/helpers/Ratchet/Mock/ConnectionDecorator.php new file mode 100644 index 0000000..5570c07 --- /dev/null +++ b/assets/php/vendor/cboden/ratchet/tests/helpers/Ratchet/Mock/ConnectionDecorator.php @@ -0,0 +1,22 @@ +<?php +namespace Ratchet\Mock; +use Ratchet\AbstractConnectionDecorator; + +class ConnectionDecorator extends AbstractConnectionDecorator { + public $last = array( + 'write' => '' + , 'end' => false + ); + + public function send($data) { + $this->last[__FUNCTION__] = $data; + + $this->getConnection()->send($data); + } + + public function close() { + $this->last[__FUNCTION__] = true; + + $this->getConnection()->close(); + } +} diff --git a/assets/php/vendor/cboden/ratchet/tests/helpers/Ratchet/Mock/WampComponent.php b/assets/php/vendor/cboden/ratchet/tests/helpers/Ratchet/Mock/WampComponent.php new file mode 100644 index 0000000..cd526cb --- /dev/null +++ b/assets/php/vendor/cboden/ratchet/tests/helpers/Ratchet/Mock/WampComponent.php @@ -0,0 +1,43 @@ +<?php +namespace Ratchet\Mock; +use Ratchet\Wamp\WampServerInterface; +use Ratchet\WebSocket\WsServerInterface; +use Ratchet\ConnectionInterface; + +class WampComponent implements WampServerInterface, WsServerInterface { + public $last = array(); + + public $protocols = array(); + + public function getSubProtocols() { + return $this->protocols; + } + + public function onCall(ConnectionInterface $conn, $id, $procURI, array $params) { + $this->last[__FUNCTION__] = func_get_args(); + } + + public function onSubscribe(ConnectionInterface $conn, $topic) { + $this->last[__FUNCTION__] = func_get_args(); + } + + public function onUnSubscribe(ConnectionInterface $conn, $topic) { + $this->last[__FUNCTION__] = func_get_args(); + } + + public function onPublish(ConnectionInterface $conn, $topic, $event, array $exclude, array $eligible) { + $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(); + } +} diff --git a/assets/php/vendor/cboden/ratchet/tests/helpers/Ratchet/NullComponent.php b/assets/php/vendor/cboden/ratchet/tests/helpers/Ratchet/NullComponent.php new file mode 100644 index 0000000..90def21 --- /dev/null +++ b/assets/php/vendor/cboden/ratchet/tests/helpers/Ratchet/NullComponent.php @@ -0,0 +1,28 @@ +<?php +namespace Ratchet; +use Ratchet\ConnectionInterface; +use Ratchet\MessageComponentInterface; +use Ratchet\WebSocket\WsServerInterface; +use Ratchet\Wamp\WampServerInterface; + +class NullComponent implements MessageComponentInterface, WsServerInterface, WampServerInterface { + public function onOpen(ConnectionInterface $conn) {} + + public function onMessage(ConnectionInterface $conn, $msg) {} + + public function onClose(ConnectionInterface $conn) {} + + public function onError(ConnectionInterface $conn, \Exception $e) {} + + public function onCall(ConnectionInterface $conn, $id, $topic, array $params) {} + + public function onSubscribe(ConnectionInterface $conn, $topic) {} + + public function onUnSubscribe(ConnectionInterface $conn, $topic) {} + + public function onPublish(ConnectionInterface $conn, $topic, $event, array $exclude = array(), array $eligible = array()) {} + + public function getSubProtocols() { + return array(); + } +} diff --git a/assets/php/vendor/cboden/ratchet/tests/helpers/Ratchet/Wamp/Stub/WsWampServerInterface.php b/assets/php/vendor/cboden/ratchet/tests/helpers/Ratchet/Wamp/Stub/WsWampServerInterface.php new file mode 100644 index 0000000..197bbd3 --- /dev/null +++ b/assets/php/vendor/cboden/ratchet/tests/helpers/Ratchet/Wamp/Stub/WsWampServerInterface.php @@ -0,0 +1,7 @@ +<?php +namespace Ratchet\Wamp\Stub; +use Ratchet\WebSocket\WsServerInterface; +use Ratchet\Wamp\WampServerInterface; + +interface WsWampServerInterface extends WsServerInterface, WampServerInterface { +} diff --git a/assets/php/vendor/cboden/ratchet/tests/helpers/Ratchet/WebSocket/Stub/WsMessageComponentInterface.php b/assets/php/vendor/cboden/ratchet/tests/helpers/Ratchet/WebSocket/Stub/WsMessageComponentInterface.php new file mode 100644 index 0000000..ef88325 --- /dev/null +++ b/assets/php/vendor/cboden/ratchet/tests/helpers/Ratchet/WebSocket/Stub/WsMessageComponentInterface.php @@ -0,0 +1,7 @@ +<?php +namespace Ratchet\WebSocket\Stub; +use Ratchet\MessageComponentInterface; +use Ratchet\WebSocket\WsServerInterface; + +interface WsMessageComponentInterface extends MessageComponentInterface, WsServerInterface { +} |