From d6f54eb17f4f150587cab29d3105b6fb40cf5962 Mon Sep 17 00:00:00 2001 From: brabli <67018167+brabli@users.noreply.github.com> Date: Wed, 9 Oct 2024 16:03:18 +0100 Subject: [PATCH] Add tests and make them pass --- src/Trait/Entity/GeocodeTrait.php | 6 +++++- tests/Trait/GeocodeTraitTest.php | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Trait/Entity/GeocodeTrait.php b/src/Trait/Entity/GeocodeTrait.php index 98c843e..4acd115 100644 --- a/src/Trait/Entity/GeocodeTrait.php +++ b/src/Trait/Entity/GeocodeTrait.php @@ -45,7 +45,11 @@ trait GeocodeTrait 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; } } diff --git a/tests/Trait/GeocodeTraitTest.php b/tests/Trait/GeocodeTraitTest.php index 03936e3..115a05b 100644 --- a/tests/Trait/GeocodeTraitTest.php +++ b/tests/Trait/GeocodeTraitTest.php @@ -89,6 +89,20 @@ final class GeocodeTraitTest extends TestCase $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 { return new class implements GeocodeInterface