Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

[DDC-1872] Overriding Mapping Annotations #414

Merged
merged 3 commits into from

4 participants

@cordoval

#412

Thanks

@travisbot

This pull request passes (merged 5d00824 into 00a5f18).

...s/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('Invalid PHP version, unable to run this test.');
@stof
stof added a note

you should change this message to be a bit more friendly, explaining that this test is only for 5.4+. The current message could let think that using 5.3 to run the testsuite is wrong, which is absolutely not the case.

@cordoval
cordoval added a note

@stof done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@cordoval

done

@travisbot

This pull request passes (merged 221ab3b into 00a5f18).

@beberlei beberlei merged commit a67a6aa into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
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;
-}
+}
Something went wrong with that request. Please try again.