pluginManager = $this->prophesize(AuthenticationPluginManagerInterface::class); $this->requestToPlugin = new RequestToHttpAuthPlugin($this->pluginManager->reveal()); } /** @test */ public function exceptionIsFoundWhenNoneOfTheSupportedMethodsIsFound(): void { $request = new ServerRequest(); $this->expectException(NoAuthenticationException::class); $this->expectExceptionMessage(sprintf( 'None of the valid authentication mechanisms where provided. Expected one of ["%s"]', implode('", "', RequestToHttpAuthPlugin::SUPPORTED_AUTH_HEADERS) )); $this->requestToPlugin->fromRequest($request); } /** * @test * @dataProvider provideHeaders */ public function properPluginIsFetchedWhenAnyAuthTypeIsFound(array $headers, string $expectedHeader): void { $request = new ServerRequest(); foreach ($headers as $header => $value) { $request = $request->withHeader($header, $value); } $plugin = $this->prophesize(AuthenticationPluginInterface::class); $getPlugin = $this->pluginManager->get($expectedHeader)->willReturn($plugin->reveal()); $this->requestToPlugin->fromRequest($request); $getPlugin->shouldHaveBeenCalledOnce(); } public function provideHeaders(): iterable { yield 'API key header only' => [[ ApiKeyHeaderPlugin::HEADER_NAME => 'foobar', ], ApiKeyHeaderPlugin::HEADER_NAME]; yield 'Authorization header only' => [[ AuthorizationHeaderPlugin::HEADER_NAME => 'foobar', ], AuthorizationHeaderPlugin::HEADER_NAME]; yield 'Both headers' => [[ AuthorizationHeaderPlugin::HEADER_NAME => 'foobar', ApiKeyHeaderPlugin::HEADER_NAME => 'foobar', ], ApiKeyHeaderPlugin::HEADER_NAME]; } }