Skip to content

Commit 6b00217

Browse files
committed
Skip empty address values in listener
1 parent b1fdb05 commit 6b00217

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Doctrine/ORM/GeocoderListener.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ private function geocodeEntity($entity)
9494
$address = $metadata->addressProperty->getValue($entity);
9595
}
9696

97+
if (empty($address)) {
98+
return;
99+
}
100+
97101
$results = $this->geocoder->geocodeQuery(GeocodeQuery::create($address));
98102

99103
if (!empty($results)) {

Tests/Doctrine/ORM/GeocoderListenerTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,18 @@ public function testPersistForInvalidGetter()
133133

134134
$this->em->flush();
135135
}
136+
137+
public function testPersistForEmptyProperty()
138+
{
139+
$dummy = new DummyWithProperty();
140+
$dummy->address = '';
141+
142+
$this->em->persist($dummy);
143+
$this->em->flush();
144+
145+
$this->assertNull($dummy->latitude);
146+
$this->assertNull($dummy->longitude);
147+
}
136148
}
137149

138150
/**

0 commit comments

Comments
 (0)