Throw exceptions when something goes wrong instead of returning null
This commit is contained in:
@@ -6,6 +6,8 @@ namespace Pcm\GeocodeBundle\Tests;
|
||||
|
||||
use Pcm\GeocodeBundle\Entity\Interface\MappableInterface;
|
||||
use Pcm\GeocodeBundle\Entity\Trait\MappableTrait;
|
||||
use Pcm\GeocodeBundle\Exception\ApiErrorException;
|
||||
use Pcm\GeocodeBundle\Exception\NoResultsFoundException;
|
||||
use Pcm\GeocodeBundle\Model\GeoCoordinates;
|
||||
use Pcm\GeocodeBundle\Service\Geocoder;
|
||||
use Pcm\GeocodeBundle\Tests\AppKernel;
|
||||
@@ -33,10 +35,20 @@ final class GeocodeTest extends KernelTestCase
|
||||
$this->assertInstanceOf(Geocoder::class, $this->geocoder);
|
||||
}
|
||||
|
||||
public function testGeocodePostcodeReturnsNullOnInvalidInput(): void
|
||||
public function testGeocodePostcodeThrowsOnEmptyInput(): void
|
||||
{
|
||||
sleep(1);
|
||||
$this->assertNull($this->geocoder->geocodePostcode(''));
|
||||
$this->expectException(ApiErrorException::class);
|
||||
$this->expectExceptionMessageMatches("/Nothing to search for.$/");
|
||||
$this->geocoder->geocodePostcode('');
|
||||
}
|
||||
|
||||
public function testGeocodePostcodeThrowsOnInvalidPostcode(): void
|
||||
{
|
||||
sleep(1);
|
||||
$this->expectException(NoResultsFoundException::class);
|
||||
$this->expectExceptionMessageMatches("/No results found.$/");
|
||||
$this->geocoder->geocodePostcode('ZZZZZZZZZZZZ');
|
||||
}
|
||||
|
||||
public function testGeocodePostcodeReturnsGeoCoordinates(): GeoCoordinates
|
||||
|
||||
Reference in New Issue
Block a user