diff --git a/Doctrine/ORM/GeocoderListener.php b/Doctrine/ORM/GeocoderListener.php index 9e485e1e..90dfe3f7 100644 --- a/Doctrine/ORM/GeocoderListener.php +++ b/Doctrine/ORM/GeocoderListener.php @@ -94,6 +94,10 @@ private function geocodeEntity($entity) $address = $metadata->addressProperty->getValue($entity); } + if (empty($address)) { + return; + } + $results = $this->geocoder->geocodeQuery(GeocodeQuery::create($address)); if (!empty($results)) { diff --git a/Tests/Doctrine/ORM/GeocoderListenerTest.php b/Tests/Doctrine/ORM/GeocoderListenerTest.php index bbad7ced..46941420 100644 --- a/Tests/Doctrine/ORM/GeocoderListenerTest.php +++ b/Tests/Doctrine/ORM/GeocoderListenerTest.php @@ -75,6 +75,7 @@ protected function setUp() $sm = new SchemaTool($this->em); $sm->createSchema([ $this->em->getClassMetadata('Bazinga\GeocoderBundle\Tests\Doctrine\ORM\DummyWithProperty'), + $this->em->getClassMetadata('Bazinga\GeocoderBundle\Tests\Doctrine\ORM\DummyWithEmptyProperty'), $this->em->getClassMetadata('Bazinga\GeocoderBundle\Tests\Doctrine\ORM\DummyWithGetter'), $this->em->getClassMetadata('Bazinga\GeocoderBundle\Tests\Doctrine\ORM\DummyWithInvalidGetter'), ]); @@ -133,6 +134,18 @@ public function testPersistForInvalidGetter() $this->em->flush(); } + + public function testPersistForEmptyProperty() + { + $dummy = new DummyWithEmptyProperty(); + $dummy->address = ''; + + $this->em->persist($dummy); + $this->em->flush(); + + $this->assertNull($dummy->latitude); + $this->assertNull($dummy->longitude); + } } /** @@ -291,3 +304,34 @@ public function setLongitude($longitude) $this->longitude = $longitude; } } + +/** + * @Geocodeable + * @Entity + */ +class DummyWithEmptyProperty +{ + /** + * @Id @GeneratedValue + * @Column(type="integer") + */ + public $id; + + /** + * @Latitude + * @Column(nullable=true) + */ + public $latitude; + + /** + * @Longitude + * @Column(nullable=true) + */ + public $longitude; + + /** + * @Address + * @Column + */ + public $address; +}