Skip to content
Browse files

Merge pull request #414 from cordoval/DDC-1872

[DDC-1872] Overriding Mapping Annotations
  • Loading branch information...
2 parents a5e043e + 221ab3b commit a67a6aa6855600199bb2cc11a3c94e31d8f80eb6 @beberlei beberlei committed Oct 6, 2012
View
12 tests/Doctrine/Tests/Models/DDC1872/DDC1872Bar.php
@@ -0,0 +1,12 @@
+<?php
+
+namespace Doctrine\Tests\Models\DDC1872;
+
+/**
+* @Entity
+*/
+class DDC1872Bar
+{
+ /** @Id @Column(type="string") */
+ private $id;
+}
View
31 tests/Doctrine/Tests/Models/DDC1872/DDC1872ExampleEntityWithOverride.php
@@ -0,0 +1,31 @@
+<?php
+
+namespace Doctrine\Tests\Models\DDC1872;
+
+/**
+ * @Entity
+ *
+ * @AttributeOverrides({
+ * @AttributeOverride(name="foo",
+ * column=@Column(
+ * name = "foo_overridden",
+ * type = "integer",
+ * length = 140,
+ * nullable = false,
+ * unique = false
+ * )
+ * )
+ * })
+ *
+ * @AssociationOverrides({
+ * @AssociationOverride(name="bar",
+ * joinColumns=@JoinColumn(
+ * name="example_entity_overridden_bar_id", referencedColumnName="id"
+ * )
+ * )
+ * })
+ */
+class DDC1872ExampleEntityWithOverride
+{
+ use DDC1872ExampleTrait;
+}
View
11 tests/Doctrine/Tests/Models/DDC1872/DDC1872ExampleEntityWithoutOverride.php
@@ -0,0 +1,11 @@
+<?php
+
+namespace Doctrine\Tests\Models\DDC1872;
+
+/**
+ * @Entity
+ */
+class DDC1872ExampleEntityWithoutOverride
+{
+ use DDC1872ExampleTrait;
+}
View
23 tests/Doctrine/Tests/Models/DDC1872/DDC1872ExampleTrait.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace Doctrine\Tests\Models\DDC1872;
+
+/**
+ * Trait class
+ */
+trait DDC1872ExampleTrait
+{
+ /** @Id @Column(type="string") */
+ private $id;
+
+ /**
+ * @Column(name="trait_foo", type="integer", length=100, nullable=true, unique=true)
+ */
+ protected $foo;
+
+ /**
+ * @OneToOne(targetEntity="DDC1872Bar", cascade={"persist", "merge"})
+ * @JoinColumn(name="example_trait_bar_id", referencedColumnName="id")
+ */
+ protected $bar;
+}
View
19 tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php
@@ -215,6 +215,23 @@ public function testInvalidFetchOptionThrowsException()
"Entity 'Doctrine\Tests\ORM\Mapping\InvalidFetchOption' has a mapping with invalid fetch mode 'eager");
$cm = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\InvalidFetchOption');
}
+
+ public function testAttributeOverridesMappingWithTrait()
+ {
+ if (!version_compare(PHP_VERSION, '5.4.0', '>=')) {
+ $this->markTestSkipped('This test is only for 5.4+.');
+ }
+
+ $factory = $this->createClassMetadataFactory();
+
+ $metadataWithoutOverride = $factory->getMetadataFor('Doctrine\Tests\Models\DDC1872\DDC1872ExampleEntityWithoutOverride');
+ $metadataWithOverride = $factory->getMetadataFor('Doctrine\Tests\Models\DDC1872\DDC1872ExampleEntityWithOverride');
+
+ $this->assertEquals('trait_foo', $metadataWithoutOverride->fieldMappings['foo']['columnName']);
+ $this->assertEquals('foo_overridden', $metadataWithOverride->fieldMappings['foo']['columnName']);
+ $this->assertArrayHasKey('example_trait_bar_id', $metadataWithoutOverride->associationMappings['bar']['joinColumnFieldNames']);
+ $this->assertArrayHasKey('example_entity_overridden_bar_id', $metadataWithOverride->associationMappings['bar']['joinColumnFieldNames']);
+ }
}
/**
@@ -337,4 +354,4 @@ class InvalidFetchOption
* @OneToMany(targetEntity="Doctrine\Tests\Models\CMS\CmsUser", fetch="eager")
*/
private $collection;
-}
+}

0 comments on commit a67a6aa

Please sign in to comment.
Something went wrong with that request. Please try again.