1
0
mirror of synced 2024-12-14 07:06:04 +03:00

Merge pull request #414 from cordoval/DDC-1872

[DDC-1872] Overriding Mapping Annotations
This commit is contained in:
Benjamin Eberlei 2012-10-06 01:35:47 -07:00
commit a67a6aa685
5 changed files with 95 additions and 1 deletions

View File

@ -0,0 +1,12 @@
<?php
namespace Doctrine\Tests\Models\DDC1872;
/**
* @Entity
*/
class DDC1872Bar
{
/** @Id @Column(type="string") */
private $id;
}

View File

@ -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 File

@ -0,0 +1,11 @@
<?php
namespace Doctrine\Tests\Models\DDC1872;
/**
* @Entity
*/
class DDC1872ExampleEntityWithoutOverride
{
use DDC1872ExampleTrait;
}

View File

@ -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 File

@ -215,6 +215,23 @@ class AnnotationDriverTest extends AbstractMappingDriverTest
"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;
}
}