createMock(LtiProvider::class); $ltiProviderMock->method('getCallbackUrl')->willReturn('clb_url'); /** @var LtiProviderService|MockObject $ltiProviderServiceMock */ $ltiProviderServiceMock = $this->createMock(LtiProviderService::class); $ltiProviderServiceMock->expects($this->once()) ->method('searchByOauthKey') ->with('key1') ->willReturn($ltiProviderMock); $dataStore = new LisOauthDataStore(); $dataStore->setServiceLocator($this->getServiceLocatorMock([ LtiProviderService::SERVICE_ID => $ltiProviderServiceMock ])); /** @noinspection PhpUnhandledExceptionInspection */ $consumer = $dataStore->lookup_consumer('key1'); $this->assertSame($ltiProviderMock, $consumer->getLtiProvider()); $this->assertSame('clb_url', $consumer->callback_url); } public function testLookupConsumerNotFound() { /** @var LtiProviderService|MockObject $ltiProviderServiceMock */ $ltiProviderServiceMock = $this->createMock(LtiProviderService::class); $ltiProviderServiceMock->expects($this->once()) ->method('searchByOauthKey') ->with('key1') ->willReturn(null); $dataStore = new LisOauthDataStore(); $dataStore->setServiceLocator($this->getServiceLocatorMock([ LtiProviderService::SERVICE_ID => $ltiProviderServiceMock ])); $this->expectException(LtiOAuthException::class); /** @noinspection PhpUnhandledExceptionInspection */ $dataStore->lookup_consumer('key1'); } public function testLookupToken() { /** @var OAuthConsumer|MockObject $oauthConsumerMock */ $oauthConsumerMock = $this->createMock(OAuthConsumer::class); $dataStore = new LisOauthDataStore(); $token = $dataStore->lookup_token($oauthConsumerMock, 'access', 'tttoken'); $this->assertInstanceOf(OAuthToken::class, $token); } public function testLookupNonce() { /** @var NoNonce|MockObject $nonceStoreMock */ $nonceStoreMock = $this->createMock(NoNonce::class); $nonceStoreMock->expects($this->once()) ->method('isValid') ->with('1234567_kkk1_nnnonnnce') ->willReturn(true); /** @var OAuthConsumer|MockObject $oauthConsumerMock */ $oauthConsumerMock = $this->createMock(OAuthConsumer::class); $oauthConsumerMock->key = 'kkk1'; $dataStore = new LisOauthDataStore(); $dataStore->setOption(LisOauthDataStore::OPTION_NONCE_STORE, $nonceStoreMock); $dataStore->setServiceLocator($this->getServiceLocatorMock([ LoggerService::SERVICE_ID => $this->createMock(LoggerService::class), ])); /** @noinspection PhpUnhandledExceptionInspection */ $res = $dataStore->lookup_nonce($oauthConsumerMock, 'token', 'nnnonnnce', '1234567'); $this->assertFalse($res); } }