Inheritance: extends AbstractTransport
Esempio n. 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);
 }
Esempio n. 2
0
 public function testInvocationError()
 {
     $dealer = new \Thruway\Role\Dealer();
     $callerTransport = new \Thruway\Transport\DummyTransport();
     $callerSession = new Session($callerTransport);
     $calleeTransport = new \Thruway\Transport\DummyTransport();
     $calleeSession = new Session($calleeTransport);
     // register from callee
     $registerMsg = new \Thruway\Message\RegisterMessage(1, new stdClass(), 'test_proc_name');
     $dealer->handleRegisterMessage(new \Thruway\Event\MessageEvent($calleeSession, $registerMsg));
     $this->assertInstanceOf('\\Thruway\\Message\\RegisteredMessage', $calleeTransport->getLastMessageSent());
     // call from one session
     $callRequestId = \Thruway\Common\Utils::getUniqueId();
     $callMsg = new \Thruway\Message\CallMessage($callRequestId, new stdClass(), 'test_proc_name');
     $dealer->handleCallMessage(new \Thruway\Event\MessageEvent($callerSession, $callMsg));
     $this->assertInstanceOf('\\Thruway\\Message\\InvocationMessage', $calleeTransport->getLastMessageSent());
     $errorMsg = \Thruway\Message\ErrorMessage::createErrorMessageFromMessage($calleeTransport->getLastMessageSent(), 'the.error.uri');
     $dealer->handleErrorMessage(new \Thruway\Event\MessageEvent($calleeSession, $errorMsg));
     /** @var \Thruway\Message\ErrorMessage $returnedError */
     $returnedError = $callerTransport->getLastMessageSent();
     $this->assertInstanceOf('\\Thruway\\Message\\ErrorMessage', $returnedError);
     $this->assertEquals(Message::MSG_CALL, $returnedError->getErrorMsgCode());
     $this->assertEquals($callRequestId, $returnedError->getErrorRequestId());
     $this->assertEquals('the.error.uri', $returnedError->getErrorURI());
 }