getMock(ClientRepositoryInterface::class); $clientRepository->method('getClientEntity')->willReturn(new ClientEntity()); $scopeRepositoryMock = $this->getMockBuilder(ScopeRepositoryInterface::class)->getMock(); $scopeRepositoryMock->method('finalizeScopes')->willReturnArgument(0); $accessRepositoryMock = $this->getMock(AccessTokenRepositoryInterface::class); $accessRepositoryMock->method('getNewToken')->willReturn(new AccessTokenEntity()); $server = new Server( $clientRepository, $accessRepositoryMock, $scopeRepositoryMock, 'file://' . __DIR__ . '/../Stubs/private.key', 'file://' . __DIR__ . '/../Stubs/public.key', new StubResponseType() ); $server->enableGrantType(new ClientCredentialsGrant(), new \DateInterval('PT1M')); $_POST['grant_type'] = 'client_credentials'; $_POST['client_id'] = 'foo'; $_POST['client_secret'] = 'bar'; $request = ServerRequestFactory::fromGlobals(); $middleware = new AuthenticationServerMiddleware($server); $response = $middleware->__invoke( $request, new Response(), function () { return func_get_args()[1]; } ); $this->assertEquals(200, $response->getStatusCode()); } public function testOAuthErrorResponse() { $clientRepository = $this->getMock(ClientRepositoryInterface::class); $clientRepository->method('getClientEntity')->willReturn(null); $server = new Server( $clientRepository, $this->getMock(AccessTokenRepositoryInterface::class), $this->getMock(ScopeRepositoryInterface::class), 'file://' . __DIR__ . '/../Stubs/private.key', 'file://' . __DIR__ . '/../Stubs/public.key', new StubResponseType() ); $server->enableGrantType(new ClientCredentialsGrant(), new \DateInterval('PT1M')); $_POST['grant_type'] = 'client_credentials'; $_POST['client_id'] = 'foo'; $_POST['client_secret'] = 'bar'; $request = ServerRequestFactory::fromGlobals(); $middleware = new AuthenticationServerMiddleware($server); $response = $middleware->__invoke( $request, new Response(), function () { return func_get_args()[1]; } ); $this->assertEquals(401, $response->getStatusCode()); } }