Files
pcm-geocode-bundle/tests/Service/GeocodeTest.php
2024-08-05 12:16:42 +01:00

58 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace Pcm\GeocodeBundle\Tests;
use Pcm\GeocodeBundle\Entity\Interface\MappableInterface;
use Pcm\GeocodeBundle\Entity\Trait\MappableTrait;
use Pcm\GeocodeBundle\Model\GeoCoordinates;
use Pcm\GeocodeBundle\Service\Geocoder;
use Pcm\GeocodeBundle\Tests\AppKernel;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
/**
* We sleep 1 second after API calls to prevent breaking the API T&Cs.
*/
final class GeocodeTest extends KernelTestCase
{
// Buckingham Palace
private const string POSTCODE = 'SW1A 1AA';
private Geocoder $geocoder;
protected function setUp(): void
{
$kernel = new AppKernel('test', false);
$kernel->boot();
$this->geocoder = $kernel->getContainer()->get('pcm_geocode.geocoder');
}
public function testGeocodeInstance(): void
{
$this->assertInstanceOf(Geocoder::class, $this->geocoder);
}
public function testGeocodePostcodeReturnsNullOnInvalidInput(): void
{
sleep(1);
$this->assertNull($this->geocoder->geocodePostcode(''));
}
public function testGeocodePostcodeReturnsGeoCoordinates(): void
{
sleep(1);
$result = $this->geocoder->geocodePostcode(self::POSTCODE);
$this->assertInstanceOf(GeoCoordinates::class, $result);
}
private function getMappableEntity(): MappableInterface
{
return new class implements MappableInterface
{
use MappableTrait;
};
}
}