/**
  * Test the getGeographicalQueryAnnotation method of the AnnotationDriver.
  */
 public function testGetGeographicalQueryAnnotation()
 {
     $this->geographicalQueryAnnotation->expects($this->once())->method('getMethod')->will($this->returnValue('getAddress'));
     $this->reader->expects($this->once())->method('getMethodAnnotation')->with($this->isInstanceOf('\\ReflectionMethod'), $this->equalTo('Vich\\GeographicalBundle\\Annotation\\GeographicalQuery'))->will($this->returnValue($this->geographicalQueryAnnotation));
     $annot = $this->driver->getGeographicalQueryAnnotation($this->geographicalEntity);
     $this->assertNotNull($annot);
     $this->assertEquals('getAddress', $annot->getMethod());
 }
 /**
  * Update coordinates on objects being updated before update
  * if they require changing
  *
  * @param PreUpdateEventArgs $args The event arguments
  */
 public function preUpdate(PreUpdateEventArgs $args)
 {
     $obj = $args->getEntity();
     $geographical = $this->driver->getGeographicalAnnotation($obj);
     if ($geographical && $geographical->getOn() === Geographical::ON_UPDATE) {
         $geographicalQuery = $this->driver->getGeographicalQueryAnnotation($obj);
         if ($geographicalQuery) {
             $this->queryCoordinates($obj, $geographical, $geographicalQuery);
         }
     }
 }
 /**
  * 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());
 }
 /**
  * Gets the latitude and longitude values of the object based on annotations.
  * 
  * @param type $obj The object
  * @return array An array
  */
 private function getLatLng($obj)
 {
     $annot = $this->driver->getGeographicalAnnotation($obj);
     if (!$annot) {
         throw new \InvalidArgumentException('Unable to find Geographical annotaion');
     }
     $latMethod = sprintf('get%s', $annot->getLat());
     $lngMethod = sprintf('get%s', $annot->getLng());
     $lat = $obj->{$latMethod}();
     $lng = $obj->{$lngMethod}();
     return array($lat, $lng);
 }