createMock(ServerRequestInterface::class); /** @var LtiProvider|MockObject $ltiProviderMock */ $ltiProviderMock = $this->createMock(LtiProvider::class); /** @var LisOAuthConsumer|MockObject $oauthConsumerMock */ $oauthConsumerMock = $this->createMock(LisOAuthConsumer::class); $oauthConsumerMock->method('getLtiProvider')->willReturn($ltiProviderMock); $oauthTokenMock = $this->createMock(OAuthToken::class); /** @var LisOauthService|MockObject $lisOauthServiceMock */ $lisOauthServiceMock = $this->createMock(LisOauthService::class); $lisOauthServiceMock->expects($this->once()) ->method('validatePsrRequest') ->with($requestMock) ->willReturn([$oauthConsumerMock, $oauthTokenMock]); $authAdapter = new LisAuthAdapter($requestMock); $authAdapter->setServiceLocator($this->getServiceLocatorMock([ LisOauthService::SERVICE_ID => $lisOauthServiceMock ])); /** @noinspection PhpUnhandledExceptionInspection */ $user = $authAdapter->authenticate(); $this->assertInstanceOf(LtiProviderUser::class, $user); $this->assertSame($ltiProviderMock, $user->getLtiProvider()); } public function testAuthenticateInvalidSignature() { /** @var ServerRequestInterface|MockObject $requestMock */ $requestMock = $this->createMock(ServerRequestInterface::class); /** @var LisOauthService|MockObject $lisOauthServiceMock */ $lisOauthServiceMock = $this->createMock(LisOauthService::class); $lisOauthServiceMock->expects($this->once()) ->method('validatePsrRequest') ->with($requestMock) ->willThrowException(new common_http_InvalidSignatureException('mmm')); $authAdapter = new LisAuthAdapter($requestMock); $authAdapter->setServiceLocator($this->getServiceLocatorMock([ LisOauthService::SERVICE_ID => $lisOauthServiceMock ])); $this->expectException(LisAuthAdapterException::class); /** @noinspection PhpUnhandledExceptionInspection */ $authAdapter->authenticate(); } }