handleCancelMessage() public method

public handleCancelMessage ( MessageEvent $event )
$event Thruway\Event\MessageEvent
示例#1
0
 public function testCancelAfterUnregister()
 {
     $dealer = new Dealer();
     $calleeTransport = new DummyTransport();
     $calleeSession = new Session($calleeTransport);
     // make sure this callee supports call cancellation
     $calleeSession->setHelloMessage(new HelloMessage('some.realm', (object) ["roles" => (object) ['callee' => (object) ['features' => (object) ['call_canceling' => true]]]]));
     $dealer->handleRegisterMessage(new MessageEvent($calleeSession, new RegisterMessage(1234, (object) [], 'some.proc')));
     $this->assertInstanceOf(RegisteredMessage::class, $calleeTransport->getLastMessageSent());
     $registrationId = $calleeTransport->getLastMessageSent()->getRegistrationId();
     $callerTransport = new DummyTransport();
     $callerSession = new Session($callerTransport);
     $callMessage = new CallMessage(2345, (object) [], 'some.proc');
     $dealer->handleCallMessage(new MessageEvent($callerSession, $callMessage));
     $this->assertInstanceOf(InvocationMessage::class, $calleeTransport->getLastMessageSent());
     $invocationId = $calleeTransport->getLastMessageSent()->getRequestId();
     // unregister
     $dealer->handleUnregisterMessage(new MessageEvent($calleeSession, new UnregisterMessage(3456, $registrationId)));
     // this may need to be addressed as the behavior of unregistration is still
     // not completely defined if you have calls pending
     $this->assertInstanceOf(UnregisteredMessage::class, $calleeTransport->getLastMessageSent());
     //$this->assertEquals(0, count($dealer->getProcedures()));
     $this->assertEquals(0, count($dealer->getProcedures()['some.proc']->getRegistrations()));
     $dealer->handleCancelMessage(new MessageEvent($callerSession, new CancelMessage(2345, (object) [])));
     $call = $dealer->getCallByRequestId(2345);
     $this->assertNotNull($call);
     $dealer->handleLeaveRealm(new LeaveRealmEvent(new Realm('some.realm'), $callerSession));
     $dealer->handleLeaveRealm(new LeaveRealmEvent(new Realm('some.realm'), $calleeSession));
     $call = $dealer->getCallByRequestId(2345);
     $this->assertNotNull($call);
 }
示例#2
0
 public function testCallCancelKillNowait()
 {
     $sessionMockBuilder = $this->getMockBuilder('\\Thruway\\Session')->setMethods(['sendMessage'])->disableOriginalConstructor();
     $eeSession = $sessionMockBuilder->getMock();
     $erSession = $sessionMockBuilder->getMock();
     $dealer = new \Thruway\Role\Dealer();
     $interruptMessage = null;
     $eeSession->expects($this->exactly(3))->method('sendMessage')->withConsecutive([$this->isInstanceOf('\\Thruway\\Message\\RegisteredMessage')], [$this->isInstanceOf('\\Thruway\\Message\\InvocationMessage')], [$this->callback(function (\Thruway\Message\InterruptMessage $msg) use(&$interruptMessage) {
         $interruptMessage = $msg;
         return true;
     })]);
     $erSession->expects($this->exactly(1))->method('sendMessage')->withConsecutive([$this->callback(function (\Thruway\Message\ErrorMessage $msg) {
         $this->assertEquals("wamp.error.canceled", $msg->getErrorURI());
         return true;
     })]);
     $registerMsg = new \Thruway\Message\RegisterMessage(12345, (object) [], 'test.procedure');
     $dealer->handleRegisterMessage(new \Thruway\Event\MessageEvent($eeSession, $registerMsg));
     $callMsg = new \Thruway\Message\CallMessage(1, (object) [], 'test.procedure');
     $dealer->handleCallMessage(new \Thruway\Event\MessageEvent($erSession, $callMsg));
     $this->assertEquals(1, $eeSession->getPendingCallCount());
     $cancelMsg = new \Thruway\Message\CancelMessage(1, (object) ["mode" => "killnowait"]);
     $eeSession->setHelloMessage($this->_helloMessage);
     $dealer->handleCancelMessage(new \Thruway\Event\MessageEvent($erSession, $cancelMsg));
     $errorMsgFromEe = \Thruway\Message\ErrorMessage::createErrorMessageFromMessage($interruptMessage);
     $errorMsgFromEe->setErrorURI("wamp.error.canceled");
     $dealer->handleErrorMessage(new \Thruway\Event\MessageEvent($eeSession, $errorMsgFromEe));
     /** @var \Thruway\Session $eeSession */
     $this->assertEquals(0, $eeSession->getPendingCallCount());
 }