First commit

This commit is contained in:
Brabli
2022-07-19 10:21:40 +01:00
commit 25c87ef115
12 changed files with 379 additions and 0 deletions

View 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;
};
}
}

View 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;
};
}
}