94 lines
2.4 KiB
PHP
94 lines
2.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Pcm\GeocodeBundle\Tests;
|
|
|
|
use Pcm\GeocodeBundle\Entity\Interface\MappableInterface;
|
|
use Pcm\GeocodeBundle\Entity\Trait\MappableTrait;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class MappableTraitTest extends TestCase
|
|
{
|
|
private const float COORD = 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::COORD));
|
|
}
|
|
|
|
public function testGetLatitudeReturnsNull(): void
|
|
{
|
|
$this->assertNull($this->obj->getLatitude());
|
|
}
|
|
|
|
public function testGetLatitude(): void
|
|
{
|
|
$this->obj->setLatitude(self::COORD);
|
|
$this->assertSame(self::COORD, $this->obj->getLatitude());
|
|
}
|
|
|
|
public function testSetLongitude(): void
|
|
{
|
|
$this->assertInstanceOf(MappableInterface::class, $this->obj->setLongitude(self::COORD));
|
|
}
|
|
|
|
public function testGetLongitudeReturnsNull(): void
|
|
{
|
|
$this->assertNull($this->obj->getLongitude());
|
|
}
|
|
|
|
public function testGetLongitude(): void
|
|
{
|
|
$this->obj->setLongitude(self::COORD);
|
|
$this->assertSame(self::COORD, $this->obj->getLongitude());
|
|
}
|
|
|
|
public function testIsGeocodedReturnsFalse(): void
|
|
{
|
|
$this->assertFalse($this->obj->isGeocoded());
|
|
}
|
|
|
|
public function testIsGeocodedReturnsFalseIfLatIsSet(): void
|
|
{
|
|
$this->obj->setLatitude(self::COORD);
|
|
$this->assertFalse($this->obj->isGeocoded());
|
|
}
|
|
|
|
public function testIsGeocodedReturnsFalseIfLonIsSet(): void
|
|
{
|
|
$this->obj->setLongitude(self::COORD);
|
|
$this->assertFalse($this->obj->isGeocoded());
|
|
}
|
|
|
|
public function testIsGeocodedReturnsTrueIfLatAndLonAreSet(): void
|
|
{
|
|
$this->obj->setLatitude(self::COORD);
|
|
$this->obj->setLongitude(self::COORD);
|
|
$this->assertTrue($this->obj->isGeocoded());
|
|
}
|
|
|
|
public function testIsGeocodeReturnsTrueIfLatAndLonAreBothZero(): void
|
|
{
|
|
$this->obj->setLatitude(0.000);
|
|
$this->obj->setLongitude(0.000);
|
|
$this->assertTrue($this->obj->isGeocoded());
|
|
}
|
|
|
|
private function getTraitObject(): MappableInterface
|
|
{
|
|
return new class implements MappableInterface
|
|
{
|
|
use MappableTrait;
|
|
};
|
|
}
|
|
}
|
|
|