Change tests to accept an interface
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user