Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added AnnotationDriver test

  • Loading branch information...
commit c9896a4ba1a8532928325714f9c8d055df6c6f59 1 parent 9a2238a
@dustin10 authored
View
155 Tests/Driver/AnnotationDriverTest.php
@@ -0,0 +1,155 @@
+<?php
+
+namespace Vich\GeographicalBundle\Tests\Driver;
+
+use Doctrine\Common\Annotations\Reader;
+use Vich\GeographicalBundle\Driver\AnnotationDriver;
+
+/**
+ * AnnotationDriverTest.
+ *
+ * @author Dustin Dobervich <ddobervich@gmail.com>
+ */
+class AnnotationDriverTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @var Doctrine\Common\Annotations\Reader $reader
+ */
+ protected $reader;
+
+ /**
+ * @var Vich\GeographicalBundle\Driver\AnnotationDriver $driver
+ */
+ protected $driver;
+
+ /**
+ * @var Vich\GeographicalBundle\Tests\DummyGeoEntity $geographicalEntity
+ */
+ protected $geographicalEntity;
+
+ /**
+ * @var Vich\GeographicalBundle\Annotation\Geographical $geographicalAnnotation
+ */
+ protected $geographicalAnnotation;
+
+ /**
+ * @var Vich\GeographicalBundle\Annotation\GeographicalQuery $geographicalQueryAnnotation
+ */
+ protected $geographicalQueryAnnotation;
+
+ /**
+ * Sets up the test.
+ */
+ protected function setUp()
+ {
+ $this->reader = $this->getMockReader();
+ $this->driver = $this->getDriver($this->reader);
+ $this->geographicalEntity = $this->getMockGeographicalEntity();
+ $this->geographicalAnnotation = $this->getMockGeographicalAnnotation();
+ $this->geographicalQueryAnnotation = $this->getMockGeographicalQueryAnnotation();
+ }
+
+ /**
+ * Test the getGeographicalAnnotation method of the AnnotationDriver.
+ */
+ public function testGetGeographicalAnnotation()
+ {
+ $this->geographicalAnnotation
+ ->expects($this->once())
+ ->method('getLat')
+ ->will($this->returnValue(50));
+
+ $this->geographicalAnnotation
+ ->expects($this->once())
+ ->method('getLng')
+ ->will($this->returnValue(-50));
+
+ $this->reader
+ ->expects($this->once())
+ ->method('getClassAnnotation')
+ ->with($this->isInstanceOf('\ReflectionClass'), $this->equalTo('Vich\GeographicalBundle\Annotation\Geographical'))
+ ->will($this->returnValue($this->geographicalAnnotation));
+
+ $annot = $this->driver->getGeographicalAnnotation($this->geographicalEntity);
+
+ $this->assertNotNull($annot);
+ $this->assertEquals(50, $annot->getLat());
+ $this->assertEquals(-50, $annot->getLng());
+ }
+
+ /**
+ * 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());
+ }
+
+ /**
+ * Gets the mock reader object.
+ *
+ * @return Doctrine\Common\Annotations\Reader The reader
+ */
+ private function getMockReader()
+ {
+ return $this->getMock('Doctrine\Common\Annotations\Reader');
+ }
+
+ /**
+ * Gets the mock driver object.
+ *
+ * @return Vich\GeographicalBundle\Driver\AnnotationDriver The driver
+ */
+ private function getDriver(Reader $reader)
+ {
+ return new AnnotationDriver($reader);
+ }
+
+ /**
+ * Gets a mock geographical entity.
+ *
+ * @return Vich\GeographicalBundle\Tests\DummyGeoEntity The entity
+ */
+ private function getMockGeographicalEntity()
+ {
+ return $this->getMock('Vich\GeographicalBundle\Tests\DummyGeoEntity');
+ }
+
+ /**
+ * Gets a mock geographical annotation.
+ *
+ * @return Vich\GeographicalBundle\Annotation\Geographical The annotation
+ */
+ private function getMockGeographicalAnnotation()
+ {
+ return $this->getMockBuilder('Vich\GeographicalBundle\Annotation\Geographical')
+ ->disableOriginalConstructor()
+ ->getMock();
+ }
+
+ /**
+ * Gets a mock geographical query annotation.
+ *
+ * @return Vich\GeographicalBundle\Annotation\GeographicalQuery The annotation
+ */
+ private function getMockGeographicalQueryAnnotation()
+ {
+ return $this->getMockBuilder('Vich\GeographicalBundle\Annotation\GeographicalQuery')
+ ->disableOriginalConstructor()
+ ->getMock();
+ }
+}
View
69 Tests/DummyGeoEntity.php
@@ -0,0 +1,69 @@
+<?php
+
+namespace Vich\GeographicalBundle\Tests;
+
+use Vich\GeographicalBundle\Annotation as Vich;
+
+/**
+ * @Vich\Geographical(on="update")
+ */
+class DummyGeoEntity
+{
+ /**
+ * @var double $latitude
+ */
+ protected $latitude = 0;
+
+ /**
+ * @var double $longitude
+ */
+ protected $longitude = 0;
+
+ /**
+ * Gets the latitude.
+ *
+ * @return double The latitude
+ */
+ public function getLatitude()
+ {
+ return $this->latitude;
+ }
+
+ /**
+ * Sets the latitude.
+ *
+ * @param double $value The latitude
+ */
+ public function setLatitude($value)
+ {
+ $this->latitude = $value;
+ }
+
+ /**
+ * Gets the longitude.
+ *
+ * @return double The longitude
+ */
+ public function getLongitude()
+ {
+ return $this->longitude;
+ }
+
+ /**
+ * Sets the longitude.
+ *
+ * @param double $value The longitude
+ */
+ public function setLongitude($value)
+ {
+ $this->longitude = $value;
+ }
+
+ /**
+ * @Vich\GeographicalQuery
+ */
+ public function getAddress()
+ {
+ return '98 Boulevard Victor Hugo 92110 Clichy, France';
+ }
+}
View
16 Tests/bootstrap.php
@@ -0,0 +1,16 @@
+<?php
+
+$vendorDir = __DIR__.'/../../../..';
+require_once $vendorDir.'/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
+
+use Symfony\Component\ClassLoader\UniversalClassLoader;
+
+$loader = new UniversalClassLoader();
+$loader->registerNamespaces(array(
+ 'Symfony' => array($vendorDir.'/symfony/src', $vendorDir.'/bundles'),
+ 'Vich' => $vendorDir.'/bundles',
+ 'Doctrine\\Common' => $vendorDir.'/doctrine-common/lib',
+ 'Doctrine\\DBAL' => $vendorDir.'/doctrine-dbal/lib',
+ 'Doctrine' => $vendorDir.'/doctrine/lib',
+));
+$loader->register();
View
17 phpunit.xml.dist
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<phpunit bootstrap="./Tests/bootstrap.php" color="true">
+ <testsuites>
+ <testsuite name="VichGeographicalBundle">
+ <directory suffix="Test.php">./Tests</directory>
+ </testsuite>
+ </testsuites>
+ <filter>
+ <whitelist>
+ <directory>./</directory>
+ <exclude>
+ <directory>./Resources</directory>
+ <directory>./Tests</directory>
+ </exclude>
+ </whitelist>
+ </filter>
+</phpunit>
Please sign in to comment.
Something went wrong with that request. Please try again.