Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #414 from cordoval/DDC-1872

[DDC-1872] Overriding Mapping Annotations
  • Loading branch information...
commit a67a6aa6855600199bb2cc11a3c94e31d8f80eb6 2 parents a5e043e + 221ab3b
Benjamin Eberlei beberlei authored
12 tests/Doctrine/Tests/Models/DDC1872/DDC1872Bar.php
... ... @@ -0,0 +1,12 @@
  1 +<?php
  2 +
  3 +namespace Doctrine\Tests\Models\DDC1872;
  4 +
  5 +/**
  6 +* @Entity
  7 +*/
  8 +class DDC1872Bar
  9 +{
  10 + /** @Id @Column(type="string") */
  11 + private $id;
  12 +}
31 tests/Doctrine/Tests/Models/DDC1872/DDC1872ExampleEntityWithOverride.php
... ... @@ -0,0 +1,31 @@
  1 +<?php
  2 +
  3 +namespace Doctrine\Tests\Models\DDC1872;
  4 +
  5 +/**
  6 + * @Entity
  7 + *
  8 + * @AttributeOverrides({
  9 + * @AttributeOverride(name="foo",
  10 + * column=@Column(
  11 + * name = "foo_overridden",
  12 + * type = "integer",
  13 + * length = 140,
  14 + * nullable = false,
  15 + * unique = false
  16 + * )
  17 + * )
  18 + * })
  19 + *
  20 + * @AssociationOverrides({
  21 + * @AssociationOverride(name="bar",
  22 + * joinColumns=@JoinColumn(
  23 + * name="example_entity_overridden_bar_id", referencedColumnName="id"
  24 + * )
  25 + * )
  26 + * })
  27 + */
  28 +class DDC1872ExampleEntityWithOverride
  29 +{
  30 + use DDC1872ExampleTrait;
  31 +}
11 tests/Doctrine/Tests/Models/DDC1872/DDC1872ExampleEntityWithoutOverride.php
... ... @@ -0,0 +1,11 @@
  1 +<?php
  2 +
  3 +namespace Doctrine\Tests\Models\DDC1872;
  4 +
  5 +/**
  6 + * @Entity
  7 + */
  8 +class DDC1872ExampleEntityWithoutOverride
  9 +{
  10 + use DDC1872ExampleTrait;
  11 +}
23 tests/Doctrine/Tests/Models/DDC1872/DDC1872ExampleTrait.php
... ... @@ -0,0 +1,23 @@
  1 +<?php
  2 +
  3 +namespace Doctrine\Tests\Models\DDC1872;
  4 +
  5 +/**
  6 + * Trait class
  7 + */
  8 +trait DDC1872ExampleTrait
  9 +{
  10 + /** @Id @Column(type="string") */
  11 + private $id;
  12 +
  13 + /**
  14 + * @Column(name="trait_foo", type="integer", length=100, nullable=true, unique=true)
  15 + */
  16 + protected $foo;
  17 +
  18 + /**
  19 + * @OneToOne(targetEntity="DDC1872Bar", cascade={"persist", "merge"})
  20 + * @JoinColumn(name="example_trait_bar_id", referencedColumnName="id")
  21 + */
  22 + protected $bar;
  23 +}
19 tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php
@@ -215,6 +215,23 @@ public function testInvalidFetchOptionThrowsException()
215 215 "Entity 'Doctrine\Tests\ORM\Mapping\InvalidFetchOption' has a mapping with invalid fetch mode 'eager");
216 216 $cm = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\InvalidFetchOption');
217 217 }
  218 +
  219 + public function testAttributeOverridesMappingWithTrait()
  220 + {
  221 + if (!version_compare(PHP_VERSION, '5.4.0', '>=')) {
  222 + $this->markTestSkipped('This test is only for 5.4+.');
  223 + }
  224 +
  225 + $factory = $this->createClassMetadataFactory();
  226 +
  227 + $metadataWithoutOverride = $factory->getMetadataFor('Doctrine\Tests\Models\DDC1872\DDC1872ExampleEntityWithoutOverride');
  228 + $metadataWithOverride = $factory->getMetadataFor('Doctrine\Tests\Models\DDC1872\DDC1872ExampleEntityWithOverride');
  229 +
  230 + $this->assertEquals('trait_foo', $metadataWithoutOverride->fieldMappings['foo']['columnName']);
  231 + $this->assertEquals('foo_overridden', $metadataWithOverride->fieldMappings['foo']['columnName']);
  232 + $this->assertArrayHasKey('example_trait_bar_id', $metadataWithoutOverride->associationMappings['bar']['joinColumnFieldNames']);
  233 + $this->assertArrayHasKey('example_entity_overridden_bar_id', $metadataWithOverride->associationMappings['bar']['joinColumnFieldNames']);
  234 + }
218 235 }
219 236
220 237 /**
@@ -337,4 +354,4 @@ class InvalidFetchOption
337 354 * @OneToMany(targetEntity="Doctrine\Tests\Models\CMS\CmsUser", fetch="eager")
338 355 */
339 356 private $collection;
340   -}
  357 +}

0 comments on commit a67a6aa

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