Files
pcm-geocode-bundle/tests/Trait/MappableTraitTest.php
2022-07-20 21:49:51 +01:00

87 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Pcm\GeocodeBundle\Tests;
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;
};
}
}