/** * Test the prePersist method of the GeographicalListener. */ public function testPrePersist() { $this->lifecycleArgs->expects($this->once())->method('getEntity')->will($this->returnValue($this->geographicalEntity)); $this->geographicalAnnotation->expects($this->once())->method('getLat')->will($this->returnValue('latitude')); $this->geographicalAnnotation->expects($this->once())->method('getLng')->will($this->returnValue('longitude')); $this->geographicalQueryAnnotation->expects($this->once())->method('getMethod')->will($this->returnValue('getAddress')); $this->queryService->expects($this->once())->method('queryForCoordinates')->with($this->anything())->will($this->returnValue($this->queryResult)); $this->queryResult->expects($this->once())->method('getLatitude')->will($this->returnValue(50)); $this->queryResult->expects($this->once())->method('getLongitude')->will($this->returnValue(-50)); $this->driver->expects($this->once())->method('getGeographicalAnnotation')->will($this->returnValue($this->geographicalAnnotation)); $this->driver->expects($this->once())->method('getGeographicalQueryAnnotation')->will($this->returnValue($this->geographicalQueryAnnotation)); $this->listener->prePersist($this->lifecycleArgs); $this->assertEquals(50, $this->geographicalEntity->getLatitude()); $this->assertEquals(-50, $this->geographicalEntity->getLongitude()); }
/** * Queries the service for coordinates. * * @param Object $entity The entity * @param Geographical $geographical The greographical annotation * @param GeographicalQuery $geographicalQuery The geogrphical query annotation */ private function queryCoordinates($entity, $geographical, $geographicalQuery) { $queryMethod = $geographicalQuery->getMethod(); $query = $entity->{$queryMethod}(); $result = $this->queryService->queryForCoordinates($query); $latSetter = 'set' . $geographical->getLat(); $lngSetter = 'set' . $geographical->getLng(); $entity->{$latSetter}($result->getLatitude()); $entity->{$lngSetter}($result->getLongitude()); }