Files
pcm-geocode-bundle/tests/Trait/GeocodeTraitTest.php

94 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
namespace Pcm\GeocodeBundle\Tests;
use Pcm\GeocodeBundle\Interface\Entity\GeocodeInterface;
use Pcm\GeocodeBundle\Trait\Entity\GeocodeTrait;
use PHPUnit\Framework\TestCase;
final class GeocodeTraitTest extends TestCase
{
private const float COORD = 123.456;
private GeocodeInterface $obj;
protected function setUp(): void
{
$this->obj = $this->getTraitObject();
}
public function testSetLatitude(): void
{
$this->assertInstanceOf(GeocodeInterface::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(GeocodeInterface::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(): GeocodeInterface
{
return new class implements GeocodeInterface
{
use GeocodeTrait;
};
}
}