Add tests and make them pass

This commit is contained in:
brabli
2024-10-09 16:03:18 +01:00
parent e302da0fa6
commit d6f54eb17f
2 changed files with 19 additions and 1 deletions

View File

@@ -45,7 +45,11 @@ trait GeocodeTrait
public function isGeocoded(): bool public function isGeocoded(): bool
{ {
return null !== $this->getLatitude() && null !== $this->getLongitude() && (0.0 !== $this->getLatitude() && 0.0 !== $this->getLongitude()); $latIsntNull = null !== $this->getLatitude();
$longIsntNull = null !== $this->getLongitude();
$bothArentZero = !(0.0 === $this->getLatitude() && 0.0 === $this->getLongitude());
return $latIsntNull && $longIsntNull && $bothArentZero;
} }
} }

View File

@@ -89,6 +89,20 @@ final class GeocodeTraitTest extends TestCase
$this->assertFalse($this->obj->isGeocoded()); $this->assertFalse($this->obj->isGeocoded());
} }
public function testIsGeocodedReturnsTrueIfLongitudeIsZeroAndLatIsNot(): void
{
$this->obj->setLatitude(0.1);
$this->obj->setLongitude(0);
$this->assertTrue($this->obj->isGeocoded());
}
public function testIsGeocodedReturnsTrueIfLatitudeIsZeroAndLongIsNot(): void
{
$this->obj->setLatitude(0);
$this->obj->setLongitude(0.2);
$this->assertTrue($this->obj->isGeocoded());
}
private function getTraitObject(): GeocodeInterface private function getTraitObject(): GeocodeInterface
{ {
return new class implements GeocodeInterface return new class implements GeocodeInterface