69 lines
1.8 KiB
PHP
69 lines
1.8 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(): GeoCoordinates
|
|
{
|
|
sleep(1);
|
|
$geoCoords = $this->geocoder->geocodePostcode(self::POSTCODE);
|
|
$this->assertNotNull($geoCoords);
|
|
|
|
return $geoCoords;
|
|
}
|
|
|
|
/**
|
|
* @depends testGeocodePostcodeReturnsGeoCoordinates
|
|
*/
|
|
public function testCoordinatesAreSet(GeoCoordinates $geoCoordinates): void
|
|
{
|
|
$this->assertIsFloat($geoCoordinates->latitude);
|
|
$this->assertIsFloat($geoCoordinates->longitude);
|
|
}
|
|
|
|
private function getMappableEntity(): MappableInterface
|
|
{
|
|
return new class implements MappableInterface
|
|
{
|
|
use MappableTrait;
|
|
};
|
|
}
|
|
}
|
|
|