From 9a7e6b01cb3b29dd5514811d9a83d966d0fe1981 Mon Sep 17 00:00:00 2001 From: Bradley Date: Thu, 26 Sep 2024 10:17:44 +0100 Subject: [PATCH] Change tests to accept an interface --- tests/Service/GeocoderTest.php | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/tests/Service/GeocoderTest.php b/tests/Service/GeocoderTest.php index 27961d9..a1c713b 100644 --- a/tests/Service/GeocoderTest.php +++ b/tests/Service/GeocoderTest.php @@ -34,8 +34,9 @@ final class GeocoderTest extends KernelTestCase { sleep(1); $this->expectException(ApiErrorException::class); + $entity = $this->createEntity(''); $this->expectExceptionMessageMatches("/Nothing to search for.$/"); - $this->geocoder->geocode(''); + $this->geocoder->geocode($entity); } public function testGeocodePostcodeThrowsOnInvalidPostcode(): void @@ -43,13 +44,15 @@ final class GeocoderTest extends KernelTestCase sleep(1); $this->expectException(NoResultsFoundException::class); $this->expectExceptionMessageMatches("/No results found.$/"); - $this->geocoder->geocode('ZZZZZZZZZZZZ'); + $entity = $this->createEntity('Invalid Postcode'); + $this->geocoder->geocode($entity); } public function testGeocodePostcodeReturnsGeoCoordinates(): GeoCoordinates { sleep(1); - $geoCoords = $this->geocoder->geocode(self::POSTCODE); + $entity = $this->createEntity(self::POSTCODE); + $geoCoords = $this->geocoder->geocode($entity); $this->assertNotNull($geoCoords); return $geoCoords; @@ -71,5 +74,23 @@ final class GeocoderTest extends KernelTestCase use GeocodeTrait; }; } + + private function createEntity(string $data): GeocodeInterface + { + $entity = new class implements GeocodeInterface { + use GeocodeTrait; + + public string $data; + + public function getGeocodeData(): string + { + return $this->data; + } + }; + + $entity->data = $data; + + return $entity; + } }