Change tests to accept an interface

This commit is contained in:
2024-09-26 10:17:44 +01:00
parent 35d5c324e2
commit 9a7e6b01cb

View File

@@ -34,8 +34,9 @@ final class GeocoderTest extends KernelTestCase
{ {
sleep(1); sleep(1);
$this->expectException(ApiErrorException::class); $this->expectException(ApiErrorException::class);
$entity = $this->createEntity('');
$this->expectExceptionMessageMatches("/Nothing to search for.$/"); $this->expectExceptionMessageMatches("/Nothing to search for.$/");
$this->geocoder->geocode(''); $this->geocoder->geocode($entity);
} }
public function testGeocodePostcodeThrowsOnInvalidPostcode(): void public function testGeocodePostcodeThrowsOnInvalidPostcode(): void
@@ -43,13 +44,15 @@ final class GeocoderTest extends KernelTestCase
sleep(1); sleep(1);
$this->expectException(NoResultsFoundException::class); $this->expectException(NoResultsFoundException::class);
$this->expectExceptionMessageMatches("/No results found.$/"); $this->expectExceptionMessageMatches("/No results found.$/");
$this->geocoder->geocode('ZZZZZZZZZZZZ'); $entity = $this->createEntity('Invalid Postcode');
$this->geocoder->geocode($entity);
} }
public function testGeocodePostcodeReturnsGeoCoordinates(): GeoCoordinates public function testGeocodePostcodeReturnsGeoCoordinates(): GeoCoordinates
{ {
sleep(1); sleep(1);
$geoCoords = $this->geocoder->geocode(self::POSTCODE); $entity = $this->createEntity(self::POSTCODE);
$geoCoords = $this->geocoder->geocode($entity);
$this->assertNotNull($geoCoords); $this->assertNotNull($geoCoords);
return $geoCoords; return $geoCoords;
@@ -71,5 +74,23 @@ final class GeocoderTest extends KernelTestCase
use GeocodeTrait; 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;
}
} }