58 lines
1.5 KiB
PHP
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\LatLongModel;
|
|
use Pcm\GeocodeBundle\Service\Geocoder;
|
|
use Pcm\GeocodeBundle\Tests\AppKernel;
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
|
|
|
/**
|
|
* Note we sleep 1s after requests to prevent breaking the API T&Cs
|
|
*/
|
|
class GeocodeTest extends KernelTestCase
|
|
{
|
|
// Buckingham Palace
|
|
private const 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 testGeocodePostcodeThrowsOnInvalidInput(): void
|
|
{
|
|
sleep(1);
|
|
$this->expectException(\Exception::class);
|
|
$this->geocoder->geocodePostcode('aaaaaaaa');
|
|
}
|
|
|
|
public function testGeocodePostcodeReturnsLatLonModel(): void
|
|
{
|
|
sleep(1);
|
|
$result = $this->geocoder->geocodePostcode(self::POSTCODE);
|
|
$this->assertInstanceOf(LatLongModel::class, $result);
|
|
}
|
|
|
|
private function getMappableEntity(): MappableInterface
|
|
{
|
|
return new class implements MappableInterface
|
|
{
|
|
use MappableTrait;
|
|
};
|
|
}
|
|
}
|