Permalink
Browse files

Referenceable child tests

- Added annotation based tests for referenceable child Documents
  • Loading branch information...
dantleech
dantleech committed Nov 1, 2012
1 parent ca47066 commit c270f940cc9fee7a4e3d645241261f4e626cc804
@@ -202,10 +202,6 @@ private function addInheritedFields(ClassMetadata $subClass, ClassMetadata $pare
$subClass->mapLifecycleCallbacks($parentClass->lifecycleCallbacks);
}
- if ($parentClass->referenceable === true && $subClass->referenceable === false) {
- throw MappingException::cannotOverrideReferenceableAsFalse($subClass->name);
- }
-
$subClass->setReferenceable($parentClass->referenceable);
}
@@ -102,9 +102,4 @@ public static function mappingFileNotFound($className, $filedName)
{
return new self("No mapping file '$filedName' found for class '$className'.");
}
-
- public static function cannotOverrideReferenceableAsFalse($className)
- {
- return new self("Child document "$className" cannot override the referenceable property to false");
- }
}
@@ -1,14 +0,0 @@
-<?php
-
-namespace Doctrine\Tests\Models\Inheritance;
-
-use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
-
-/**
- * @PHPCRODM\Document(referenceable=false)
- */
-class NonReferenceableChildDocument extends ReferenceableParentDocument
-{
-}
-
-
@@ -1,22 +0,0 @@
-<?php
-
-namespace Documents;
-
-namespace Doctrine\Tests\Models\Inheritance;
-
-use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
-
-/**
- * @PHPCRODM\Document(referenceable=true)
- */
-class ReferenceableParentDocument
-{
- /** @PHPCRODM\Id(strategy="repository") */
- public $id;
-
- public function getId()
- {
- return $this->id;
- }
-}
-
@@ -57,22 +57,35 @@ public function testCacheDriver()
$this->markTestIncomplete('Test cache driver setting and handling.');
}
- /**
- * @expectedException Doctrine\Common\Persistence\Mapping\MappingException
- */
- public function testAddInheritedFields()
+ public function testLoadMetadata_referenceableChildOverriddenAsFalse()
{
- $parentClass = 'Doctrine\Tests\Models\Inheritance\ReferenceableParentDocument';
- $childClass = 'Doctrine\Tests\Models\Inheritance\NonReferenceableChildDocument';
+ // if the child class overrides referenceable as false it is not taken into account
+ // as we only ever set the referenceable property to TRUE. This prevents us from
+ // knowing if the user has explicitly set referenceable to FALSE on a child entity.
+
+ $cache = new \Doctrine\Common\Cache\ArrayCache();
+ $reader = new \Doctrine\Common\Annotations\AnnotationReader($cache);
+ $annotationDriver = new \Doctrine\ODM\PHPCR\Mapping\Driver\AnnotationDriver($reader);
+ $annotationDriver->addPaths(array(__DIR__ . '/Model'));
+ $this->dm->getConfiguration()->setMetadataDriverImpl($annotationDriver);
- $driver = new \Doctrine\Common\Persistence\Mapping\Driver\PHPDriver(array(__DIR__ . '/Model/php'));
- $this->dm->getConfiguration()->setMetadataDriverImpl($driver);
+ $cmf = new ClassMetadataFactory($this->dm);
+ $meta = $cmf->getMetadataFor('Doctrine\Tests\ODM\PHPCR\Mapping\Model\ReferenceableChildReferenceableFalseMappingObject');
+
+ $this->assertTrue($meta->referenceable);
+ }
+
+ public function testLoadMetadata_referenceableChild()
+ {
+ $cache = new \Doctrine\Common\Cache\ArrayCache();
+ $reader = new \Doctrine\Common\Annotations\AnnotationReader($cache);
+ $annotationDriver = new \Doctrine\ODM\PHPCR\Mapping\Driver\AnnotationDriver($reader);
+ $annotationDriver->addPaths(array(__DIR__ . '/Model'));
+ $this->dm->getConfiguration()->setMetadataDriverImpl($annotationDriver);
- $parent = new \Doctrine\ODM\PHPCR\Mapping\ClassMetadata($parentClass);
- $child = new \Doctrine\ODM\PHPCR\Mapping\ClassMetadata($childClass);
$cmf = new ClassMetadataFactory($this->dm);
- $cmf->setMetadataFor($parent->name, $parent);
- $cmf->setMetadataFor($child->name, $child);
- $meta = $cmf->loadMetadata($child->name);
+ $meta = $cmf->getMetadataFor('Doctrine\Tests\ODM\PHPCR\Mapping\Model\ReferenceableChildMappingObject');
+
+ $this->assertTrue($meta->referenceable);
}
}
@@ -0,0 +1,18 @@
+<?php
+
+namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model;
+
+use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
+
+/**
+ * Object which extends a referenceable object and so should also
+ * be referenceable.
+ *
+ * @PHPCRODM\Document()
+ */
+class ReferenceableChildMappingObject extends ReferenceableMappingObject
+{
+ /** @PHPCRODM\Id */
+ public $id;
+}
+
@@ -0,0 +1,18 @@
+<?php
+
+namespace Doctrine\Tests\ODM\PHPCR\Mapping\Model;
+
+use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
+
+/**
+ * An object that extends a referenceable object but sets
+ * referenceable to FALSE, which is not permitted.
+ *
+ * @PHPCRODM\Document(referenceable=false)
+ */
+class ReferenceableChildReferenceableFalseMappingObject extends ReferenceableMappingObject
+{
+ /** @PHPCRODM\Id */
+ public $id;
+}
+

0 comments on commit c270f94

Please sign in to comment.