From f5445d606b08f0e17ddcbd5940f94a623ec19750 Mon Sep 17 00:00:00 2001 From: Timo Michna Date: Sat, 1 Oct 2016 11:41:42 +0200 Subject: [PATCH 01/11] fixed population of list results --- src/Tidal/WampWatch/SubscriptionMonitor.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Tidal/WampWatch/SubscriptionMonitor.php b/src/Tidal/WampWatch/SubscriptionMonitor.php index 426f6bb..061395b 100644 --- a/src/Tidal/WampWatch/SubscriptionMonitor.php +++ b/src/Tidal/WampWatch/SubscriptionMonitor.php @@ -15,9 +15,7 @@ use Tidal\WampWatch\ClientSessionInterface as ClientSession; /** - * Description of SessionMonitor. - * - * @author Timo + * Class SubscriptionMonitor */ class SubscriptionMonitor implements MonitorInterface { @@ -138,8 +136,11 @@ protected function getList() protected function getSubscriptionIdRetrievalCallback() { - return function ($res) { - $this->setList($res); + + return function (\Thruway\CallResult $res) { + /** @var \Thruway\Message\ResultMessage $message */ + $message = $res->getResultMessage(); + $this->setList($message->getArguments()[0]); $this->emit('list', [ $this->subscriptionIds->exact, $this->subscriptionIds->prefix, From 194a60ee1571d52b17ce34a12c4d733a978b31c6 Mon Sep 17 00:00:00 2001 From: Timo Michna Date: Sat, 1 Oct 2016 13:32:50 +0200 Subject: [PATCH 02/11] added CrossbarTestingTrait --- .../crossbar/CrossbarTestingTrait.php | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 tests/integration/crossbar/CrossbarTestingTrait.php diff --git a/tests/integration/crossbar/CrossbarTestingTrait.php b/tests/integration/crossbar/CrossbarTestingTrait.php new file mode 100644 index 0000000..12151e0 --- /dev/null +++ b/tests/integration/crossbar/CrossbarTestingTrait.php @@ -0,0 +1,75 @@ + + * * + * * For the full copyright and license information, please view the LICENSE + * * file that was distributed with this source code. + * + */ + +namespace integration\crossbar; + +use Psr\Log\NullLogger; +use Thruway\Logging\Logger; +use Thruway\Connection; +use React\EventLoop\Factory as LoopFactory; +use React\EventLoop\LoopInterface; + +trait CrossbarTestingTrait +{ + /** + * @var Connection + */ + private $connection; + + /** + * @var LoopInterface + */ + private $loop; + + /** + * @var int + */ + private $clientSessionId = -1; + + /** + * @var int + */ + private $monitoredSessionId = -2; + + private function setupConnection() + { + + $this->clientSessionId = -1; + $this->monitoredSessionId = -2; + + Logger::set(new NullLogger()); + + $this->loop = LoopFactory::create(); + + $this->connection = $this->createConnection($this->loop); + + } + + /** + * @param \React\EventLoop\LoopInterface|null $loop + * + * @return \Thruway\Connection + */ + private function createConnection(LoopInterface $loop = null) + { + if ($loop === null) { + $loop = LoopFactory::create(); + } + + return new Connection( + [ + 'realm' => self::REALM_NAME, + 'url' => self::ROUTER_URL, + ], + $loop + ); + } +} \ No newline at end of file From 7a3c7eb5839153f57c090911587f147a0de990f2 Mon Sep 17 00:00:00 2001 From: Timo Michna Date: Sat, 1 Oct 2016 13:33:25 +0200 Subject: [PATCH 03/11] made use of CrossbarTestingTrait --- .../crossbar/CrosssbarSessionMonitorTest.php | 57 +++---------------- 1 file changed, 7 insertions(+), 50 deletions(-) diff --git a/tests/integration/crossbar/CrosssbarSessionMonitorTest.php b/tests/integration/crossbar/CrosssbarSessionMonitorTest.php index 28a6f58..8a8bfd6 100644 --- a/tests/integration/crossbar/CrosssbarSessionMonitorTest.php +++ b/tests/integration/crossbar/CrosssbarSessionMonitorTest.php @@ -3,59 +3,31 @@ namespace integration\crossbar; require_once realpath(__DIR__ . "/../..") . "/bootstrap.php"; +require_once __DIR__ . "/CrossbarTestingTrait.php"; - -use Psr\Log\NullLogger; -use Thruway\Logging\Logger; use Thruway\ClientSession; -use Thruway\Connection; -use React\EventLoop\Factory as LoopFactory; -use React\EventLoop\LoopInterface; use Tidal\WampWatch\SessionMonitor; use Tidal\WampWatch\Adapter\Thruway\ClientSession as Adapter; class CrosssbarSessionMonitorTest extends \PHPUnit_Framework_TestCase { + use CrossbarTestingTrait; const REALM_NAME = 'realm1'; const ROUTER_URL = 'ws://127.0.0.1:8080/ws'; /** - * @var Connection - */ - private $connection; - - /** - * @var LoopInterface + * */ - private $loop; - - /** - * @var int - */ - private $clientSessionId = -1; - - /** - * @var int - */ - private $monitoredSessionId = -2; - public function setup() { - - $this->clientSessionId = -1; - $this->monitoredSessionId = -2; - - Logger::set(new NullLogger()); - - $this->loop = LoopFactory::create(); - - $this->connection = $this->createConnection($this->loop); - + $this->setupConnection(); } - + /** + * + */ public function test_onstart() { @@ -176,19 +148,4 @@ public function test_onleave() } - private function createConnection(LoopInterface $loop = null) - { - if ($loop = null) { - $loop = LoopFactory::create(); - } - - return new Connection( - [ - 'realm' => self::REALM_NAME, - 'url' => self::ROUTER_URL, - ], - $loop - ); - } - } From df62593a854e51fc0f775f4778ba78da3e6f877c Mon Sep 17 00:00:00 2001 From: Timo Michna Date: Sat, 1 Oct 2016 13:35:39 +0200 Subject: [PATCH 04/11] added CrosssbarSubscriptionMonitorTest --- .../CrosssbarSubscriptionMonitorTest.php | 327 ++++++++++++++++++ 1 file changed, 327 insertions(+) create mode 100644 tests/integration/crossbar/CrosssbarSubscriptionMonitorTest.php diff --git a/tests/integration/crossbar/CrosssbarSubscriptionMonitorTest.php b/tests/integration/crossbar/CrosssbarSubscriptionMonitorTest.php new file mode 100644 index 0000000..c2aba97 --- /dev/null +++ b/tests/integration/crossbar/CrosssbarSubscriptionMonitorTest.php @@ -0,0 +1,327 @@ + + * * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +namespace integration\crossbar; + +require_once realpath(__DIR__ . "/../..") . "/bootstrap.php"; +require_once __DIR__ . "/CrossbarTestingTrait.php"; + +use Thruway\ClientSession; +use Tidal\WampWatch\SubscriptionMonitor; +use Tidal\WampWatch\Adapter\Thruway\ClientSession as Adapter; +use Tidal\WampWatch\Util; + +class CrosssbarSubscriptionMonitorTest extends \PHPUnit_Framework_TestCase +{ + + use CrossbarTestingTrait; + + const REALM_NAME = 'realm1'; + + const ROUTER_URL = 'ws://127.0.0.1:8080/ws'; + + public function setup() + { + $this->setupConnection(); + } + + public function test_onstart() + { + + $subscriptionInfo = null; + + $this->connection->on('open', function (ClientSession $session) use (&$subscriptionInfo) { + + $subscriptionMonitor = new SubscriptionMonitor(new Adapter($session)); + + $subscriptionMonitor->on('start', function ($ids) use (&$subscriptionInfo, $subscriptionMonitor) { + + $subscriptionInfo = $ids; + + $subscriptionMonitor->stop(); + $this->connection->close(); + }); + + $subscriptionMonitor->on('error', function ($error) use (&$subscriptionInfo, $subscriptionMonitor) { + + var_dump($error); + + $this->connection->close(); + + die(); + }); + + $subscriptionMonitor->start(); + }); + + $this->connection->on('error', function ($reason) { + echo "The connected has closed with error: {$reason}\n"; + }); + + $this->connection->open(); + + $this->assertInstanceOf(\stdClass::class, $subscriptionInfo); + $this->assertAttributeInternalType('array', 'exact', $subscriptionInfo); + $this->assertAttributeInternalType('array', 'prefix', $subscriptionInfo); + $this->assertAttributeInternalType('array', 'wildcard', $subscriptionInfo); + } + + public function test_oncreate() + { + $subscriptionSessionId = null; + $subscriptionInfo = null; + + $this->connection->on('open', function (ClientSession $session) use (&$subscriptionInfo, &$subscriptionSessionId) { + + $subscriptionMonitor = new SubscriptionMonitor(new Adapter($session)); + + $subscriptionMonitor->on('start', function () use ($subscriptionMonitor) { + + // create an additional client session + $clientConnection = $this->createConnection(); + + $clientConnection->on('open', function (ClientSession $clientSession) use ($clientConnection) { + $this->clientSessionId = $clientSession->getSessionId(); + $clientSession->subscribe('foo', function () { + }); + $clientConnection->close(); + }); + $clientConnection->open(); + + $subscriptionMonitor->stop(); + $this->connection->close(); + }); + + $subscriptionMonitor->on('create', function ($sessionId, \stdClass $subInfo) use (&$subscriptionInfo, &$subscriptionSessionId, $subscriptionMonitor) { + + $subscriptionInfo = $subInfo; + $subscriptionSessionId = $sessionId; + + $subscriptionMonitor->stop(); + $this->connection->close(); + }); + + $subscriptionMonitor->on('error', function ($error) use (&$subscriptionInfo, $subscriptionMonitor) { + + var_dump($error); + + $this->connection->close(); + }); + + $subscriptionMonitor->start(); + + }); + + $this->connection->on('error', function ($reason) { + echo "The connected has closed with error: {$reason}\n"; + }); + + $this->connection->open(); + + $this->assertInternalType('int', $subscriptionSessionId); + $this->assertInstanceOf(\stdClass::class, $subscriptionInfo); + $this->assertAttributeEquals('foo', 'uri', $subscriptionInfo); + $this->assertAttributeEquals('exact', 'match', $subscriptionInfo); + $this->assertAttributeInternalType('int', 'id', $subscriptionInfo); + $this->assertAttributeInternalType('string', 'created', $subscriptionInfo); + } + + public function test_onsubscribe() + { + $sessionId = null; + $subscriptionId = null; + + $this->connection->on('open', function (ClientSession $session) use (&$sessionId, &$subscriptionId) { + + $subscriptionMonitor = new SubscriptionMonitor(new Adapter($session)); + + $subscriptionMonitor->on('start', function () use ($subscriptionMonitor) { + + // create an additional client session + $clientConnection = $this->createConnection(); + + $clientConnection->on('open', function (ClientSession $clientSession) use ($clientConnection) { + $this->clientSessionId = $clientSession->getSessionId(); + $clientSession->subscribe('foo', function () { + }); + $clientConnection->close(); + }); + $clientConnection->open(); + + $subscriptionMonitor->stop(); + $this->connection->close(); + }); + + $subscriptionMonitor->on('subscribe', function ($sesId, $subId) use (&$sessionId, &$subscriptionId, $subscriptionMonitor) { + + $sessionId = $sesId; + $subscriptionId = $subId; + + $subscriptionMonitor->stop(); + $this->connection->close(); + }); + + $subscriptionMonitor->on('error', function ($error) use ($subscriptionMonitor) { + + var_dump($error); + $subscriptionMonitor->stop(); + $this->connection->close(); + }); + + $subscriptionMonitor->start(); + + }); + + $this->connection->on('error', function ($reason) { + echo "The connected has closed with error: {$reason}\n"; + }); + + $this->connection->open(); + + $this->assertInternalType('int', $sessionId); + $this->assertInternalType('int', $subscriptionId); + } + + public function test_onunsubscribe() + { + + $sessionId = null; + $subscriptionId = null; + + $this->connection->on('open', function (ClientSession $session) use (&$sessionId, &$subscriptionId) { + + $subscriptionMonitor = new SubscriptionMonitor(new Adapter($session)); + + // create an additional client session + $clientConnection = $this->createConnection(); + $clientSession = null; + + $subscriptionMonitor->on('start', function () use ($subscriptionMonitor, $clientConnection, $clientConnection) { + $clientConnection->open(); + + $subscriptionMonitor->stop(); + $this->connection->close(); + }); + + $clientConnection->on('open', function (ClientSession $clientSession) use ($clientConnection, &$subscriptionMonitor) { + + $this->clientSessionId = $clientSession->getSessionId(); + + $subscriptionMonitor->on('subscribe', function () use ($clientSession) { + Util::unsubscribe(new Adapter($clientSession), func_get_args()[1]); + }); + + $clientSession->subscribe('foo', function () { + }); + + $clientConnection->close(); + + }); + + $subscriptionMonitor->on('unsubscribe', function ($sesId, $subId) use (&$sessionId, &$subscriptionId, $subscriptionMonitor, $clientConnection) { + + $sessionId = $sesId; + $subscriptionId = $subId; + + $clientConnection->close(); + $subscriptionMonitor->stop(); + $this->connection->close(); + }); + + $subscriptionMonitor->on('error', function ($error) use ($subscriptionMonitor) { + + var_dump($error); + $subscriptionMonitor->stop(); + $this->connection->close(); + }); + + $subscriptionMonitor->start(); + + }); + + $this->connection->on('error', function ($reason) { + echo "The connected has closed with error: {$reason}\n"; + }); + + $this->connection->open(); + + $this->assertInternalType('int', $sessionId); + $this->assertInternalType('int', $subscriptionId); + } + + public function test_ondelete() + { + $sessionId = null; + $subscriptionId = null; + + $this->connection->on('open', function (ClientSession $session) use (&$sessionId, &$subscriptionId) { + + $subscriptionMonitor = new SubscriptionMonitor(new Adapter($session)); + + // create an additional client session + $clientConnection = $this->createConnection(); + $clientSession = null; + + $subscriptionMonitor->on('start', function () use ($subscriptionMonitor, $clientConnection, $clientConnection) { + $clientConnection->open(); + + $subscriptionMonitor->stop(); + $this->connection->close(); + }); + + $clientConnection->on('open', function (ClientSession $clientSession) use ($clientConnection, &$subscriptionMonitor) { + + $topicName = bin2hex(random_bytes(10)); + $this->clientSessionId = $clientSession->getSessionId(); + + $subscriptionMonitor->on('subscribe', function () use ($clientSession) { + Util::unsubscribe(new Adapter($clientSession), func_get_args()[1]); + }); + + $clientSession->subscribe($topicName, function () { + }); + + $clientConnection->close(); + + }); + + $subscriptionMonitor->on('delete', function ($sesId, $subId) use (&$sessionId, &$subscriptionId, $subscriptionMonitor, $clientConnection) { + + $sessionId = $sesId; + $subscriptionId = $subId; + + $clientConnection->close(); + $subscriptionMonitor->stop(); + $this->connection->close(); + }); + + $subscriptionMonitor->on('error', function ($error) use ($subscriptionMonitor) { + + var_dump($error); + $subscriptionMonitor->stop(); + $this->connection->close(); + }); + + $subscriptionMonitor->start(); + + }); + + $this->connection->on('error', function ($reason) { + echo "The connected has closed with error: {$reason}\n"; + }); + + $this->connection->open(); + + $this->assertInternalType('int', $sessionId); + $this->assertInternalType('int', $subscriptionId); + } + +} From c4548a47cc8063c05010f40940bf6b2c0d14e576 Mon Sep 17 00:00:00 2001 From: Timo Michna Date: Sat, 1 Oct 2016 13:43:42 +0200 Subject: [PATCH 05/11] added .codeclimate.yml --- .codeclimate.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .codeclimate.yml diff --git a/.codeclimate.yml b/.codeclimate.yml new file mode 100644 index 0000000..d0b733a --- /dev/null +++ b/.codeclimate.yml @@ -0,0 +1,17 @@ +--- +engines: + duplication: + enabled: true + config: + languages: + - php + fixme: + enabled: true + phpmd: + enabled: true +ratings: + paths: + - "**.php" +exclude_paths: +- tests/ +- examples/ From 2d12ad4f6c35b4bc078c035f5516c3ef0ff774a4 Mon Sep 17 00:00:00 2001 From: Timo Michna Date: Sat, 1 Oct 2016 11:47:13 +0000 Subject: [PATCH 06/11] Applied fixes from StyleCI --- .../Adapter/React/DeferredAdapter.php | 19 ++++++++----------- .../Adapter/React/PromiseAdapter.php | 16 +++++++--------- .../WampWatch/Async/DeferredInterface.php | 15 +++++++-------- .../WampWatch/Async/PromiseInterface.php | 12 ++++++------ .../WampWatch/Stub/ClientSessionStub.php | 1 + src/Tidal/WampWatch/SubscriptionMonitor.php | 3 +-- 6 files changed, 30 insertions(+), 36 deletions(-) diff --git a/src/Tidal/WampWatch/Adapter/React/DeferredAdapter.php b/src/Tidal/WampWatch/Adapter/React/DeferredAdapter.php index daf69d0..42eb9bc 100644 --- a/src/Tidal/WampWatch/Adapter/React/DeferredAdapter.php +++ b/src/Tidal/WampWatch/Adapter/React/DeferredAdapter.php @@ -1,11 +1,11 @@ * - * * This file is part of the Tidal/WampWatch package. - * * (c) 2016 Timo Michna - * * - * * For the full copyright and license information, please view the LICENSE - * * file that was distributed with this source code. + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. * */ @@ -13,19 +13,17 @@ use Tidal\WampWatch\Async\DeferredInterface; use Tidal\WampWatch\Async\PromiseInterface; - use React\Promise\Deferred; class DeferredAdapter implements DeferredInterface { - /** * @var Deferred */ private $adaptee; /** - * @var string fully qualified class name of the promise to create. + * @var string fully qualified class name of the promise to create */ private $promiseClass = PromiseAdapter::class; @@ -112,5 +110,4 @@ private function createPromise() $this->adaptee->promise() ); } - -} \ No newline at end of file +} diff --git a/src/Tidal/WampWatch/Adapter/React/PromiseAdapter.php b/src/Tidal/WampWatch/Adapter/React/PromiseAdapter.php index bad3b0b..ae5ecae 100644 --- a/src/Tidal/WampWatch/Adapter/React/PromiseAdapter.php +++ b/src/Tidal/WampWatch/Adapter/React/PromiseAdapter.php @@ -1,11 +1,11 @@ * - * * This file is part of the Tidal/WampWatch package. - * * (c) 2016 Timo Michna - * * - * * For the full copyright and license information, please view the LICENSE - * * file that was distributed with this source code. + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. * */ @@ -14,10 +14,8 @@ use Tidal\WampWatch\Async\PromiseInterface; use React\Promise\Promise; - class PromiseAdapter implements PromiseInterface { - /** * @var Promise */ @@ -112,4 +110,4 @@ public function progress(callable $onProgress) return $this; } -} \ No newline at end of file +} diff --git a/src/Tidal/WampWatch/Async/DeferredInterface.php b/src/Tidal/WampWatch/Async/DeferredInterface.php index 13c90c7..020d4b1 100644 --- a/src/Tidal/WampWatch/Async/DeferredInterface.php +++ b/src/Tidal/WampWatch/Async/DeferredInterface.php @@ -1,17 +1,16 @@ * - * * This file is part of the Tidal/WampWatch package. - * * (c) 2016 Timo Michna - * * - * * For the full copyright and license information, please view the LICENSE - * * file that was distributed with this source code. + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. * */ namespace Tidal\WampWatch\Async; - interface DeferredInterface { /** @@ -33,4 +32,4 @@ public function reject($reason = null); * @param null $update */ public function notify($update = null); -} \ No newline at end of file +} diff --git a/src/Tidal/WampWatch/Async/PromiseInterface.php b/src/Tidal/WampWatch/Async/PromiseInterface.php index 363cd8b..dd77ef1 100644 --- a/src/Tidal/WampWatch/Async/PromiseInterface.php +++ b/src/Tidal/WampWatch/Async/PromiseInterface.php @@ -1,11 +1,11 @@ * - * * This file is part of the Tidal/WampWatch package. - * * (c) 2016 Timo Michna - * * - * * For the full copyright and license information, please view the LICENSE - * * file that was distributed with this source code. + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. * */ diff --git a/src/Tidal/WampWatch/Stub/ClientSessionStub.php b/src/Tidal/WampWatch/Stub/ClientSessionStub.php index 3939b60..8149781 100644 --- a/src/Tidal/WampWatch/Stub/ClientSessionStub.php +++ b/src/Tidal/WampWatch/Stub/ClientSessionStub.php @@ -404,6 +404,7 @@ public static function getUniqueId() /** * @param $msg + * * @return mixed */ public function sendMessage($msg) diff --git a/src/Tidal/WampWatch/SubscriptionMonitor.php b/src/Tidal/WampWatch/SubscriptionMonitor.php index 061395b..9a579cf 100644 --- a/src/Tidal/WampWatch/SubscriptionMonitor.php +++ b/src/Tidal/WampWatch/SubscriptionMonitor.php @@ -15,7 +15,7 @@ use Tidal\WampWatch\ClientSessionInterface as ClientSession; /** - * Class SubscriptionMonitor + * Class SubscriptionMonitor. */ class SubscriptionMonitor implements MonitorInterface { @@ -136,7 +136,6 @@ protected function getList() protected function getSubscriptionIdRetrievalCallback() { - return function (\Thruway\CallResult $res) { /** @var \Thruway\Message\ResultMessage $message */ $message = $res->getResultMessage(); From b52f53a2a21d5c3bcc993f36e649ec61b947deb3 Mon Sep 17 00:00:00 2001 From: Timo Michna Date: Sat, 1 Oct 2016 13:53:05 +0200 Subject: [PATCH 07/11] formatting --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c9b4bcf..293c0e4 100644 --- a/README.md +++ b/README.md @@ -13,4 +13,5 @@ WAMP router meta-events ([registration](https://tools.ietf.org/html/draft-oberstet-hybi-tavendo-wamp-02#section-13.3.7), [subscription](https://tools.ietf.org/html/draft-oberstet-hybi-tavendo-wamp-02#section-13.6.3), [session](https://tools.ietf.org/html/draft-oberstet-hybi-tavendo-wamp-02#section-13.7.1)) + \ No newline at end of file From fc13a1bef810e28c48e8932329e81278e952056b Mon Sep 17 00:00:00 2001 From: Timo Michna Date: Sat, 1 Oct 2016 13:55:23 +0200 Subject: [PATCH 08/11] v0.5.1 --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb90ae9..13fdea1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ +### [0.5.1] - 2016-10-01 + + * added integration test for subscription monitor + * added configuration for codeclimate + ### [0.5.0] - 2016-09-28 * added DeferredInterface From dac5bc01e0918f7f4ce598c34e1dc1bec70b71e6 Mon Sep 17 00:00:00 2001 From: Timo Michna Date: Sat, 1 Oct 2016 14:44:56 +0200 Subject: [PATCH 09/11] fixed SubscriptionMonitor amd tests --- src/Tidal/WampWatch/SubscriptionMonitor.php | 5 ++- tests/unit/SubscriptionMonitorTest.php | 50 +++++++++++++++++++-- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/Tidal/WampWatch/SubscriptionMonitor.php b/src/Tidal/WampWatch/SubscriptionMonitor.php index 9a579cf..c138d76 100644 --- a/src/Tidal/WampWatch/SubscriptionMonitor.php +++ b/src/Tidal/WampWatch/SubscriptionMonitor.php @@ -139,14 +139,15 @@ protected function getSubscriptionIdRetrievalCallback() return function (\Thruway\CallResult $res) { /** @var \Thruway\Message\ResultMessage $message */ $message = $res->getResultMessage(); - $this->setList($message->getArguments()[0]); + $list = $message->getArguments()[0]; + $this->setList($list); $this->emit('list', [ $this->subscriptionIds->exact, $this->subscriptionIds->prefix, $this->subscriptionIds->wildcard, ]); - return $res; + return $list; }; } } diff --git a/tests/unit/SubscriptionMonitorTest.php b/tests/unit/SubscriptionMonitorTest.php index 8541833..b370b95 100644 --- a/tests/unit/SubscriptionMonitorTest.php +++ b/tests/unit/SubscriptionMonitorTest.php @@ -6,6 +6,8 @@ use Tidal\WampWatch\SubscriptionMonitor; use Tidal\WampWatch\Stub\ClientSessionStub; +use Thruway\CallResult; +use Thruway\Message\ResultMessage; class SubscriptionMonitorTest extends \PHPUnit_Framework_TestCase @@ -143,7 +145,7 @@ public function test_start_event_after_running() $stub->completeSubscription(SubscriptionMonitor::SUBSCRIPTION_SUB_TOPIC); $stub->completeSubscription(SubscriptionMonitor::SUBSCRIPTION_UNSUB_TOPIC); - $this->assertEquals($subIdMap, $response); + $this->assertEquals($subIdMap->getResultMessage()->getArguments()[0], $response); } // META SUBSCRIPTION AND CALL TESTS @@ -366,7 +368,7 @@ public function test_get_seesion_ids_returns_subscription_map() $stub->respondToCall(SubscriptionMonitor::SUBSCRIPTION_LIST_TOPIC, $subIdMap); - $this->assertSame($subIdMap, $res); + $this->assertEquals($subIdMap->getResultMessage()->getArguments()[0], $res); } public function test_2nd_get_seesion_ids_returns_subscription_map_locally() @@ -387,7 +389,7 @@ public function test_2nd_get_seesion_ids_returns_subscription_map_locally() $second = $r; }); - $this->assertSame($first, $second); + $this->assertEquals($first, $second); } @@ -403,7 +405,47 @@ private function getSubscriptionInfo() private function getSubscriptionIdMap() { - return json_decode('{"exact": [321], "prefix": [654], "wildcard": [987]}'); + return $this->getCallResultMock(); } + /** + * @return \PHPUnit_Framework_MockObject_MockObject|CallResult + */ + private function getCallResultMock() + { + $mock = $this->getMockBuilder(CallResult::class) + ->disableOriginalConstructor() + ->getMock(); + + $mock->expects($this->any()) + ->method('getResultMessage') + ->willReturn( + $this->getResultMessageMock() + ); + + return $mock; + } + + /** + * @return \PHPUnit_Framework_MockObject_MockObject| + */ + private function getResultMessageMock() + { + $mock = $this->getMockBuilder(ResultMessage::class) + ->disableOriginalConstructor() + ->getMock(); + + $mock->expects($this->any()) + ->method('getArguments') + ->willReturn( + [ + json_decode('{"exact": [321], "prefix": [654], "wildcard": [987]}') + ] + ); + + return $mock; + } + + + } From 395819db4b6a0b1d38c3ee696f308fe9d9840938 Mon Sep 17 00:00:00 2001 From: Timo Michna Date: Sat, 1 Oct 2016 14:53:51 +0200 Subject: [PATCH 10/11] fixed CrosssbarSubscriptionMonitorTest --- tests/integration/crossbar/CrosssbarSubscriptionMonitorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/crossbar/CrosssbarSubscriptionMonitorTest.php b/tests/integration/crossbar/CrosssbarSubscriptionMonitorTest.php index c2aba97..05a9f99 100644 --- a/tests/integration/crossbar/CrosssbarSubscriptionMonitorTest.php +++ b/tests/integration/crossbar/CrosssbarSubscriptionMonitorTest.php @@ -279,7 +279,7 @@ public function test_ondelete() $clientConnection->on('open', function (ClientSession $clientSession) use ($clientConnection, &$subscriptionMonitor) { - $topicName = bin2hex(random_bytes(10)); + $topicName = "foo-bar-baz-boo"; $this->clientSessionId = $clientSession->getSessionId(); $subscriptionMonitor->on('subscribe', function () use ($clientSession) { From 386a24231f3c8c8f942ebba798d72321eacfb6cc Mon Sep 17 00:00:00 2001 From: Timo Michna Date: Sat, 1 Oct 2016 15:07:29 +0200 Subject: [PATCH 11/11] v0.5.1 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13fdea1..4ecee68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ * added integration test for subscription monitor * added configuration for codeclimate + * bug fixes ### [0.5.0] - 2016-09-28