First commit
This commit is contained in:
55
tests/Service/GeocodeTest.php
Normal file
55
tests/Service/GeocodeTest.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\tests\Service;
|
||||
|
||||
use Pcm\GeocodeBundle\Entity\GeocodeData;
|
||||
use Pcm\GeocodeBundle\Geocoder;
|
||||
use Pcm\GeocodeBundle\Interface\MappableInterface;
|
||||
use Pcm\GeocodeBundle\Trait\MappableTrait;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class GeocodeTest extends TestCase
|
||||
{
|
||||
// Buckingham Palace
|
||||
private const POSTCODE = 'SW1A 1AA';
|
||||
|
||||
/**
|
||||
* @var \Pcm\GeocodeBundle\Geocoder
|
||||
*/
|
||||
private Geocoder $geocoder;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->geocoder = new Geocoder();
|
||||
}
|
||||
|
||||
public function testGeocodeInstance(): void
|
||||
{
|
||||
$this->assertInstanceOf(\Pcm\GeocodeBundle\Geocoder::class, $this->geocoder);
|
||||
}
|
||||
|
||||
public function testGeocodePostcodeThrowsOnInvalidInput(): void
|
||||
{
|
||||
sleep(1);
|
||||
$this->expectException(\Exception::class);
|
||||
$this->geocoder->geocodePostcode('aaaaaaaa');
|
||||
}
|
||||
|
||||
public function testGeocodePostcodeReturnsGeocodeObject(): void
|
||||
{
|
||||
sleep(1);
|
||||
$result = $this->geocoder->geocodePostcode(self::POSTCODE);
|
||||
$this->assertInstanceOf(GeocodeData::class, $result);
|
||||
}
|
||||
|
||||
private function getMappableEntity(): MappableInterface
|
||||
{
|
||||
return new class implements MappableInterface
|
||||
{
|
||||
use MappableTrait;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
86
tests/Trait/MappableTraitTest.php
Normal file
86
tests/Trait/MappableTraitTest.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\tests\Trait;
|
||||
|
||||
use Pcm\GeocodeBundle\Interface\MappableInterface;
|
||||
use Pcm\GeocodeBundle\Trait\MappableTrait;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class MappableTraitTest extends TestCase
|
||||
{
|
||||
private const FLOAT = 123.456;
|
||||
|
||||
private MappableInterface $obj;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->obj = $this->getTraitObject();
|
||||
}
|
||||
|
||||
public function testSetLatitude(): void
|
||||
{
|
||||
$this->assertInstanceOf(MappableInterface::class, $this->obj->setLatitude(self::FLOAT));
|
||||
}
|
||||
|
||||
public function testGetLatitudeReturnsNull(): void
|
||||
{
|
||||
$this->assertNull($this->obj->getLatitude());
|
||||
}
|
||||
|
||||
public function testGetLatitude(): void
|
||||
{
|
||||
$this->obj->setLatitude(self::FLOAT);
|
||||
$this->assertSame(self::FLOAT, $this->obj->getLatitude());
|
||||
}
|
||||
|
||||
public function testSetLongitude(): void
|
||||
{
|
||||
$this->assertInstanceOf(MappableInterface::class, $this->obj->setLongitude(self::FLOAT));
|
||||
}
|
||||
|
||||
public function testGetLongitudeReturnsNull(): void
|
||||
{
|
||||
$this->assertNull($this->obj->getLongitude());
|
||||
}
|
||||
|
||||
public function testGetLongitude(): void
|
||||
{
|
||||
$this->obj->setLongitude(self::FLOAT);
|
||||
$this->assertSame(self::FLOAT, $this->obj->getLongitude());
|
||||
}
|
||||
|
||||
public function testIsGeocodedReturnsFalse(): void
|
||||
{
|
||||
$this->assertFalse($this->obj->isGeocoded());
|
||||
}
|
||||
|
||||
public function testIsGeocodedReturnsFalseIfLatIsSet(): void
|
||||
{
|
||||
$this->obj->setLatitude(self::FLOAT);
|
||||
$this->assertFalse($this->obj->isGeocoded());
|
||||
}
|
||||
|
||||
public function testIsGeocodedReturnsFalseIfLonIsSet(): void
|
||||
{
|
||||
$this->obj->setLongitude(self::FLOAT);
|
||||
$this->assertFalse($this->obj->isGeocoded());
|
||||
}
|
||||
|
||||
public function testIsGeocodedReturnsTrueIfLatAndLonAreSet(): void
|
||||
{
|
||||
$this->obj->setLatitude(self::FLOAT);
|
||||
$this->obj->setLongitude(self::FLOAT);
|
||||
$this->assertTrue($this->obj->isGeocoded());
|
||||
}
|
||||
|
||||
private function getTraitObject(): MappableInterface
|
||||
{
|
||||
return new class implements MappableInterface
|
||||
{
|
||||
use MappableTrait;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user