diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f829c0..6858211 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,4 +9,7 @@ This changelog is initialized in release 1.0.0 ## [Unreleased] +### Added +* Generic geocoder service + [Unreleased]: https://github.com/wimski/nominatim-geocoding-api-client/compare/v1.0.0...master diff --git a/README.md b/README.md index ceb5cba..c6a840b 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,7 @@ $service = new NominatimGeocoderService( Services for the following providers are currently available: * [Nominatim](https://nominatim.org/release-docs/latest/api/Overview/) * [LocationIQ](https://locationiq.com/docs) +* Generic: without any implementation specific headers or parameters. Custom services can easily be created by extending the `AbstractGeocoderService` as long as the provider implements the Nominatim spec correctly. diff --git a/src/Config/GenericConfig.php b/src/Config/GenericConfig.php new file mode 100644 index 0000000..722f8f8 --- /dev/null +++ b/src/Config/GenericConfig.php @@ -0,0 +1,11 @@ +config; + } +} diff --git a/tests/Config/GenericConfigTest.php b/tests/Config/GenericConfigTest.php new file mode 100644 index 0000000..5295f12 --- /dev/null +++ b/tests/Config/GenericConfigTest.php @@ -0,0 +1,29 @@ +getUrl()); + static::assertSame('/fowarding', $config->getForwardGeocodingEndpoint()); + static::assertSame('/reversing', $config->getReverseGeocodingEndpoint()); + static::assertSame('nl', $config->getLanguage()); + } +} diff --git a/tests/GeocoderServices/GenericGeocoderServiceTest.php b/tests/GeocoderServices/GenericGeocoderServiceTest.php new file mode 100644 index 0000000..9abcf20 --- /dev/null +++ b/tests/GeocoderServices/GenericGeocoderServiceTest.php @@ -0,0 +1,135 @@ +client = Mockery::mock(ClientInterface::class); + $this->responseTransformer = Mockery::mock(GeocodingResponseTransformerInterface::class); + $this->config = Mockery::mock(GenericConfigInterface::class); + + $this->config + ->shouldReceive('getUrl')->once()->andReturn('https://generic.server/')->getMock() + ->shouldReceive('getLanguage')->once()->andReturn('nl')->getMock(); + + $this->service = new GenericGeocoderService( + $this->client, + $this->responseTransformer, + $this->config, + ); + } + + /** + * @test + */ + public function it_makes_a_forward_geocoding_request(): void + { + $response = Mockery::mock(ResponseInterface::class); + + $this->config + ->shouldReceive('getForwardGeocodingEndpoint') + ->once() + ->andReturn('/forwards'); + + $this->client + ->shouldReceive('request') + ->once() + ->with('https://generic.server/forwards', [ + 'Accept-Language' => 'nl', + ], [ + 'param' => 'value', + 'format' => 'json', + ]) + ->andReturn($response); + + $this->responseTransformer + ->shouldReceive('transformForwardResponse') + ->once() + ->with($response) + ->andReturn(Mockery::mock(ForwardGeocodingResponseInterface::class)); + + /** @var ForwardGeocodingRequestParametersInterface|MockInterface $parameters */ + $parameters = Mockery::mock(ForwardGeocodingRequestParametersInterface::class) + ->shouldReceive('toArray') + ->once() + ->andReturn(['param' => 'value']) + ->getMock(); + + $this->service->requestForwardGeocoding($parameters); + } + + /** + * @test + */ + public function it_makes_a_reverse_geocoding_request(): void + { + $response = Mockery::mock(ResponseInterface::class); + + $this->config + ->shouldReceive('getReverseGeocodingEndpoint') + ->once() + ->andReturn('/reversed'); + + $this->client + ->shouldReceive('request') + ->once() + ->with('https://generic.server/reversed', [ + 'Accept-Language' => 'nl', + ], [ + 'param' => 'value', + 'format' => 'json', + ]) + ->andReturn($response); + + $this->responseTransformer + ->shouldReceive('transformReverseResponse') + ->once() + ->with($response) + ->andReturn(Mockery::mock(ReverseGeocodingResponseInterface::class)); + + /** @var ReverseGeocodingRequestParametersInterface|MockInterface $parameters */ + $parameters = Mockery::mock(ReverseGeocodingRequestParametersInterface::class) + ->shouldReceive('toArray') + ->once() + ->andReturn(['param' => 'value']) + ->getMock(); + + $this->service->requestReverseGeocoding($parameters); + } +}