Selaa lähdekoodia

[mapping] started updating mapping and tests for compatibility with new annotation reader

gediminasm 13 vuotta sitten
vanhempi
commit
29d252db45

+ 5 - 5
bin/vendors.php

@@ -10,11 +10,11 @@ if (!is_dir(VENDOR_PATH)) {
 }
 
 $deps = array(
-    array('doctrine-orm', 'http://github.com/doctrine/doctrine2.git', '550fcbc17fc9d927edf3'),
-    array('doctrine-dbal', 'http://github.com/doctrine/dbal.git', 'eb80a3797e80fbaa024bb0a1ef01c3d81bb68a76'),
-    array('doctrine-common', 'http://github.com/doctrine/common.git', '73b61b50782640358940'),
-    array('doctrine-mongodb', 'http://github.com/doctrine/mongodb.git', '4109734e249a951f270c531999871bfe9eeed843'),
-    array('doctrine-mongodb-odm', 'http://github.com/doctrine/mongodb-odm.git', '8fb97a4740c2c12a2a5a4e7d78f0717847c39691'),
+    array('doctrine-orm', 'http://github.com/doctrine/doctrine2.git', '15562d030e'),
+    array('doctrine-dbal', 'http://github.com/doctrine/dbal.git', '537de7e'),
+    array('doctrine-common', 'http://github.com/doctrine/common.git', 'b3b1e62b1c'/*b385ca7708*/),
+    array('doctrine-mongodb', 'http://github.com/doctrine/mongodb.git', '1674e629f2'),
+    array('doctrine-mongodb-odm', 'http://github.com/doctrine/mongodb-odm.git', '1674e629f2'),
 
     array('Symfony/Component/ClassLoader', 'http://github.com/symfony/ClassLoader.git', '6894a17bb88831f2d260c7b9897862e5ccf35bae'),
     array('Symfony/Component/Console', 'http://github.com/symfony/Console.git', '55344823ce1c2a780c9137d86143d9084209a02d'),

+ 1 - 6
lib/Gedmo/Mapping/MappedEventSubscriber.php

@@ -195,8 +195,7 @@ abstract class MappedEventSubscriber implements EventSubscriber
     {
         if (null === $this->defaultAnnotationReader) {
             if (version_compare(\Doctrine\Common\Version::VERSION, '2.2.0-DEV', '>=')) {
-                $reader = new \Doctrine\Common\Annotations\SimpleAnnotationReader();
-                $reader->addNamespace('Doctrine\ORM\Mapping');
+                $reader = new \Doctrine\Common\Annotations\AnnotationReader();
                 \Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace(
                     'Gedmo\\Mapping\\Annotation',
                     __DIR__ . '/../../'
@@ -217,10 +216,6 @@ abstract class MappedEventSubscriber implements EventSubscriber
                 $reader->setAnnotationNamespaceAlias('Gedmo\\Mapping\\Annotation\\', 'gedmo');
                 $reader->setEnableParsePhpImports(false);
                 $reader->setAutoloadAnnotations(true);
-                /*\Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace(
-                    'Gedmo\\Mapping\\Annotation',
-                    __DIR__ . '/../../'
-                );*/
                 $reader = new \Doctrine\Common\Annotations\CachedReader(
                     new \Doctrine\Common\Annotations\IndexedReader($reader), new ArrayCache()
                 );

+ 5 - 5
lib/Gedmo/Translatable/Entity/AbstractTranslation.php

@@ -8,10 +8,10 @@ use Doctrine\ORM\Mapping\Id;
 use Doctrine\ORM\Mapping\GeneratedValue;
 
 /**
-* Gedmo\Translatable\Entity\AbstractTranslation
-*
-* @MappedSuperclass
-*/
+ * Gedmo\Translatable\Entity\AbstractTranslation
+ *
+ * @MappedSuperclass
+ */
 abstract class AbstractTranslation
 {
     /**
@@ -47,7 +47,7 @@ abstract class AbstractTranslation
     /**
      * @var string $foreignKey
      *
-     * @Column(name="foreign_key", type="string", length="64")
+     * @Column(name="foreign_key", type="string", length=64)
      */
     private $foreignKey;
 

+ 2 - 8
tests/Gedmo/Mapping/MappingTest.php

@@ -27,20 +27,14 @@ class MappingTest extends \PHPUnit_Framework_TestCase
         $config = new \Doctrine\ORM\Configuration();
         $config->setProxyDir(TESTS_TEMP_DIR);
         $config->setProxyNamespace('Gedmo\Mapping\Proxy');
-        \Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace(
-            'Gedmo\\Mapping\\Annotation',
-            VENDOR_PATH . '/../lib'
-        );
-        $this->markTestSkipped('Skipping according to a bug in annotation reader creation.');
-        $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver());
+        //$this->markTestSkipped('Skipping according to a bug in annotation reader creation.');
+        $config->setMetadataDriverImpl(new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($_ENV['annotation_reader']));
 
         $conn = array(
             'driver' => 'pdo_sqlite',
             'memory' => true,
         );
 
-        //$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
-
         $evm = new \Doctrine\Common\EventManager();
         $evm->addEventSubscriber(new \Gedmo\Translatable\TranslationListener());
         $this->timestampable = new \Gedmo\Timestampable\TimestampableListener();

+ 3 - 0
tests/Gedmo/Mapping/Mock/Extension/Encoder/Mapping/Annotations.php

@@ -6,6 +6,9 @@ namespace Gedmo\Mapping\Mock\Extension\Encoder\Mapping;
 
 use Doctrine\Common\Annotations\Annotation;
 
+/**
+ * @Annotation
+ */
 final class Encode extends Annotation
 {
     public $type = 'md5';

+ 7 - 7
tests/Gedmo/Sortable/Fixture/Category.php

@@ -17,32 +17,32 @@ class Category
      * @ORM\Column(type="integer")
      */
     private $id;
-    
+
     /**
-     * @ORM\Column(type="string", length="255")
+     * @ORM\Column(type="string", length=255)
      */
     private $name;
-    
+
     /**
      * @ORM\OneToMany(targetEntity="Item", mappedBy="category")
      */
     private $items;
-    
+
     public function __construct()
     {
         $this->items = new ArrayCollection();
     }
-    
+
     public function getId()
     {
         return $this->id;
     }
-    
+
     public function setName($name)
     {
         $this->name = $name;
     }
-    
+
     public function getName()
     {
         return $this->name;

+ 11 - 11
tests/Gedmo/Sortable/Fixture/Item.php

@@ -16,54 +16,54 @@ class Item
      * @ORM\Column(type="integer")
      */
     private $id;
-    
+
     /**
-     * @ORM\Column(type="string", length="255")
+     * @ORM\Column(type="string", length=255)
      */
     private $name;
-    
+
     /**
      * @Gedmo\SortablePosition
      * @ORM\Column(type="integer")
      */
     private $position;
-    
+
     /**
      * @Gedmo\SortableGroup
      * @ORM\ManyToOne(targetEntity="Category", inversedBy="items")
      */
     private $category;
-    
+
     public function getId()
     {
         return $this->id;
     }
-    
+
     public function setName($name)
     {
         $this->name = $name;
     }
-    
+
     public function getName()
     {
         return $this->name;
     }
-    
+
     public function setPosition($position)
     {
         $this->position = $position;
     }
-    
+
     public function getPosition()
     {
         return $this->position;
     }
-    
+
     public function setCategory(Category $category)
     {
         $this->category = $category;
     }
-    
+
     public function getCategory()
     {
         return $this->category;

+ 10 - 10
tests/Gedmo/Sortable/Fixture/Node.php

@@ -18,52 +18,52 @@ class Node
     private $id;
 
     /**
-     * @ORM\Column(type="string", length="255")
+     * @ORM\Column(type="string", length=255)
      */
     private $name;
 
     /**
      * @Gedmo\SortableGroup
-     * @ORM\Column(type="string", length="255")
+     * @ORM\Column(type="string", length=255)
      */
     private $path;
-    
+
     /**
      * @Gedmo\SortablePosition
      * @ORM\Column(type="integer")
      */
     private $position;
-    
+
     public function getId()
     {
         return $this->id;
     }
-    
+
     public function setName($name)
     {
         $this->name = $name;
     }
-    
+
     public function getName()
     {
         return $this->name;
     }
-    
+
     public function setPath($path)
     {
         $this->path = $path;
     }
-    
+
     public function getPath()
     {
         return $this->path;
     }
-    
+
     public function setPosition($position)
     {
         $this->position = $position;
     }
-    
+
     public function getPosition()
     {
         return $this->position;

+ 4 - 7
tests/Gedmo/Tool/BaseTestCaseMongoODM.php

@@ -38,6 +38,9 @@ abstract class BaseTestCaseMongoODM extends \PHPUnit_Framework_TestCase
         if (!class_exists('Mongo')) {
             $this->markTestSkipped('Missing Mongo extension.');
         }
+        if (version_compare(\Doctrine\Common\Version::VERSION, '2.2.0-DEV', '>=')) {
+            $this->markTestSkipped('ODM does not support version 2.2 of doctrine common.');
+        }
     }
 
     /**
@@ -100,13 +103,7 @@ abstract class BaseTestCaseMongoODM extends \PHPUnit_Framework_TestCase
      */
     protected function getMetadataDriverImplementation()
     {
-        $reader = new AnnotationReader();
-        \Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace(
-            'Gedmo\\Mapping\\Annotation',
-            VENDOR_PATH . '/../lib'
-        );
-        //$reader->setAutoloadAnnotations(true);
-        return new AnnotationDriver($reader);
+        return new AnnotationDriver($_ENV['annotation_reader']);
     }
 
     /**

+ 5 - 14
tests/Gedmo/Tool/BaseTestCaseOM.php

@@ -55,6 +55,9 @@ abstract class BaseTestCaseOM extends \PHPUnit_Framework_TestCase
         if (!class_exists('Mongo')) {
             $this->markTestSkipped('Missing Mongo extension.');
         }
+        if (version_compare(\Doctrine\Common\Version::VERSION, '2.2.0-DEV', '>=')) {
+            $this->markTestSkipped('ODM does not support version 2.2 of doctrine common.');
+        }
     }
 
     /**
@@ -175,13 +178,7 @@ abstract class BaseTestCaseOM extends \PHPUnit_Framework_TestCase
      */
     protected function getDefaultORMMetadataDriverImplementation()
     {
-        $reader = new AnnotationReader();
-        \Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace(
-            'Gedmo\\Mapping\\Annotation',
-            VENDOR_PATH . '/../lib'
-        );
-        //$reader->setAutoloadAnnotations(true);
-        return new AnnotationDriverORM($reader);
+        return new AnnotationDriverORM($_ENV['annotation_reader']);
     }
 
     /**
@@ -191,13 +188,7 @@ abstract class BaseTestCaseOM extends \PHPUnit_Framework_TestCase
      */
     protected function getDefaultMongoODMMetadataDriverImplementation()
     {
-        $reader = new AnnotationReader();
-        \Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace(
-            'Gedmo\\Mapping\\Annotation',
-            VENDOR_PATH . '/../lib'
-        );
-        //$reader->setAutoloadAnnotations(true);
-        return new AnnotationDriverODM($reader);
+        return new AnnotationDriverODM($_ENV['annotation_reader']);
     }
 
     /**

+ 27 - 17
tests/Gedmo/Tool/BaseTestCaseORM.php

@@ -172,13 +172,7 @@ abstract class BaseTestCaseORM extends \PHPUnit_Framework_TestCase
      */
     protected function getMetadataDriverImplementation()
     {
-        $reader = new AnnotationReader();
-        \Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace(
-            'Gedmo\\Mapping\\Annotation',
-            VENDOR_PATH . '/../lib'
-        );
-        //$reader->setAutoloadAnnotations(true);
-        return new AnnotationDriver($reader);
+        return new AnnotationDriver($_ENV['annotation_reader']);
     }
 
     /**
@@ -212,27 +206,43 @@ abstract class BaseTestCaseORM extends \PHPUnit_Framework_TestCase
     private function getMockAnnotatedConfig()
     {
         $config = $this->getMock('Doctrine\ORM\Configuration');
-        $config->expects($this->once())
+        $config
+            ->expects($this->once())
             ->method('getProxyDir')
-            ->will($this->returnValue(__DIR__.'/../../temp'));
+            ->will($this->returnValue(__DIR__.'/../../temp'))
+        ;
 
-        $config->expects($this->once())
+        $config
+            ->expects($this->once())
             ->method('getProxyNamespace')
-            ->will($this->returnValue('Proxy'));
+            ->will($this->returnValue('Proxy'))
+        ;
 
-        $config->expects($this->once())
+        $config
+            ->expects($this->once())
             ->method('getAutoGenerateProxyClasses')
-            ->will($this->returnValue(true));
+            ->will($this->returnValue(true))
+        ;
 
-        $config->expects($this->once())
+        $config
+            ->expects($this->once())
             ->method('getClassMetadataFactoryName')
-            ->will($this->returnValue('Doctrine\\ORM\\Mapping\\ClassMetadataFactory'));
+            ->will($this->returnValue('Doctrine\\ORM\\Mapping\\ClassMetadataFactory'))
+        ;
 
         $mappingDriver = $this->getMetadataDriverImplementation();
 
-        $config->expects($this->any())
+        $config
+            ->expects($this->any())
             ->method('getMetadataDriverImpl')
-            ->will($this->returnValue($mappingDriver));
+            ->will($this->returnValue($mappingDriver))
+        ;
+
+        $config
+            ->expects($this->any())
+            ->method('getDefaultRepositoryClassName')
+            ->will($this->returnValue('Doctrine\\ORM\\EntityRepository'))
+        ;
 
         return $config;
     }

+ 16 - 23
tests/Gedmo/Tree/ConcurrencyTest.php

@@ -36,7 +36,8 @@ class ConcurrencyTest extends BaseTestCaseORM
 
     public function testConcurrentEntitiesInOneFlush()
     {
-        $sport = $this->em->getRepository(self::CATEGORY)->find(2);
+        $repo = $this->em->getRepository(self::CATEGORY);
+        $sport = $repo->findOneByTitle('Root2');
         $sport->setTitle('Sport');
 
         $skiing = new Category();
@@ -74,14 +75,14 @@ class ConcurrencyTest extends BaseTestCaseORM
         $this->em->clear();
 
         $meta = $this->em->getClassMetadata(self::CATEGORY);
-        $sport = $this->em->getRepository(self::CATEGORY)->find(2);
+        $sport = $repo->findOneByTitle('Sport');
         $left = $meta->getReflectionProperty('lft')->getValue($sport);
         $right = $meta->getReflectionProperty('rgt')->getValue($sport);
 
         $this->assertEquals($left, 9);
         $this->assertEquals($right, 16);
 
-        $skiing = $this->em->getRepository(self::CATEGORY)->find(6);
+        $skiing = $repo->findOneByTitle('Skiing');
         $left = $meta->getReflectionProperty('lft')->getValue($skiing);
         $right = $meta->getReflectionProperty('rgt')->getValue($skiing);
 
@@ -91,36 +92,28 @@ class ConcurrencyTest extends BaseTestCaseORM
 
     public function testConcurrentTree()
     {
+        $repo = $this->em->getRepository(self::CATEGORY);
         $meta = $this->em->getClassMetadata(self::CATEGORY);
 
-        $root = $this->em->getRepository(self::CATEGORY)->find(1);
-        $left = $meta->getReflectionProperty('lft')->getValue($root);
-        $right = $meta->getReflectionProperty('rgt')->getValue($root);
+        $root = $repo->findOneByTitle('Root');
 
-        $this->assertEquals($left, 1);
-        $this->assertEquals($right, 8);
+        $this->assertEquals($root->getLeft(), 1);
+        $this->assertEquals($root->getRight(), 8);
 
-        $root2 = $this->em->getRepository(self::CATEGORY)->find(2);
-        $left = $meta->getReflectionProperty('lft')->getValue($root2);
-        $right = $meta->getReflectionProperty('rgt')->getValue($root2);
+        $root2 = $repo->findOneByTitle('Root2');
 
-        $this->assertEquals($left, 9);
-        $this->assertEquals($right, 10);
+        $this->assertEquals($root2->getLeft(), 9);
+        $this->assertEquals($root2->getRight(), 10);
 
-        $child2Child = $this->em->getRepository(self::CATEGORY)->find(5);
-        $left = $meta->getReflectionProperty('lft')->getValue($child2Child);
-        $right = $meta->getReflectionProperty('rgt')->getValue($child2Child);
+        $child2Child = $repo->findOneByTitle('childs2_child');
 
-        $this->assertEquals($left, 5);
-        $this->assertEquals($right, 6);
+        $this->assertEquals($child2Child->getLeft(), 5);
+        $this->assertEquals($child2Child->getRight(), 6);
 
         $child2Parent = $child2Child->getParent();
-        $child2Parent->getId(); // initialize if proxy
-        $left = $meta->getReflectionProperty('lft')->getValue($child2Parent);
-        $right = $meta->getReflectionProperty('rgt')->getValue($child2Parent);
 
-        $this->assertEquals($left, 4);
-        $this->assertEquals($right, 7);
+        $this->assertEquals($child2Parent->getLeft(), 4);
+        $this->assertEquals($child2Parent->getRight(), 7);
     }
 
     protected function getUsedEntityFixtures()

+ 1 - 1
tests/Gedmo/Tree/Fixture/User.php

@@ -12,7 +12,7 @@ class User extends Role {
   const PASSWORD_SALT = 'dfJko$~346958rg!DFT]AEtzserf9giq)3/TAeg;aDFa43';
 
   /**
-   * @ORM\Column(name="email", type="string", unique="true")
+   * @ORM\Column(name="email", type="string", unique=true)
    * @var string
    */
   private $email;

+ 1 - 1
tests/Gedmo/Tree/MultiInheritanceTest3.php

@@ -39,7 +39,7 @@ class MultiInheritanceTest3 extends BaseTestCaseORM
     {
         $this->populate();
         $carRepo = $this->em->getRepository(self::CAR);
-        $audi = $carRepo->find(2);
+        $audi = $carRepo->findOneByTitle('Audi-80');
         $this->assertEquals(2, $carRepo->childCount($audi));
         $this->assertEquals(1, $audi->getLeft());
         $this->assertEquals(6, $audi->getRight());

+ 13 - 0
tests/bootstrap.php

@@ -54,3 +54,16 @@ $loader->register();
 
 Gedmo\Version::checkODMMongoDBDependencies();
 Gedmo\Version::checkORMDependencies();
+
+\Doctrine\Common\Annotations\AnnotationRegistry::registerFile(
+    VENDOR_PATH.'/doctrine-orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'
+);
+
+\Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace(
+    'Gedmo\\Mapping\\Annotation',
+    VENDOR_PATH.'/../lib'
+);
+
+$reader = new \Doctrine\Common\Annotations\AnnotationReader();
+$reader = new \Doctrine\Common\Annotations\CachedReader($reader, new \Doctrine\Common\Cache\ArrayCache());
+$_ENV['annotation_reader'] = $reader;