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);
}