/** * Issue 53 - publishing inside of subscription event callback * prevents other internal clients from receiving the published event * * @depends testStart * @param \Thruway\Peer\Router $router */ public function testIssue53(\Thruway\Peer\Router $router) { $this->_callCount = 0; $transport1 = $this->getMockBuilder('\\Thruway\\Transport\\TransportInterface')->getMock(); $transport2 = $this->getMockBuilder('\\Thruway\\Transport\\TransportInterface')->getMock(); $transport2->expects($this->exactly(3))->method('sendMessage')->withConsecutive([$this->isInstanceOf('\\Thruway\\Message\\WelcomeMessage')], [$this->isInstanceOf('\\Thruway\\Message\\SubscribedMessage')], [$this->isInstanceOf('\\Thruway\\Message\\EventMessage')]); $transportPublisher = $this->getMockBuilder('\\Thruway\\Transport\\TransportInterface')->getMock(); $session1 = new \Thruway\Session($transport1); $session2 = new \Thruway\Session($transport2); $sessionPublisher = new \Thruway\Session($transportPublisher); $transport1->expects($this->exactly(3))->method('sendMessage')->withConsecutive([$this->isInstanceOf('\\Thruway\\Message\\WelcomeMessage')], [$this->isInstanceOf('\\Thruway\\Message\\SubscribedMessage')], [$this->callback(function ($arg) use($router, $transport1, $session1) { $this->assertInstanceOf('\\Thruway\\Message\\EventMessage', $arg); // publish while in the callback $publishMsg = new \Thruway\Message\PublishMessage(12346, (object) [], 'com.example.nowhere'); $session1->dispatchMessage($publishMsg); $this->_callCount = $this->_callCount + 1; return true; })]); $router->getEventDispatcher()->dispatch("connection_open", new \Thruway\Event\ConnectionOpenEvent($session1)); $router->getEventDispatcher()->dispatch("connection_open", new \Thruway\Event\ConnectionOpenEvent($session2)); $router->getEventDispatcher()->dispatch("connection_open", new \Thruway\Event\ConnectionOpenEvent($sessionPublisher)); // send in a few hellos $helloMsg = new \Thruway\Message\HelloMessage("realm_issue53", (object) []); $session1->dispatchMessage($helloMsg); $session2->dispatchMessage($helloMsg); $sessionPublisher->dispatchMessage($helloMsg); // subscribe $subscribeMsg = new \Thruway\Message\SubscribeMessage(\Thruway\Common\Utils::getUniqueId(), (object) [], "com.example.issue53"); $session1->dispatchMessage($subscribeMsg); $session2->dispatchMessage($subscribeMsg); // publish to the topic from the publishing transport $publishMsg = new \Thruway\Message\PublishMessage(12345, (object) [], 'com.example.issue53'); $sessionPublisher->dispatchMessage($publishMsg); }