Merge pull request #414 from cordoval/DDC-1872
[DDC-1872] Overriding Mapping Annotations
This commit is contained in:
commit
a67a6aa685
12
tests/Doctrine/Tests/Models/DDC1872/DDC1872Bar.php
Normal file
12
tests/Doctrine/Tests/Models/DDC1872/DDC1872Bar.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\DDC1872;
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class DDC1872Bar
|
||||
{
|
||||
/** @Id @Column(type="string") */
|
||||
private $id;
|
||||
}
|
@ -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;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\DDC1872;
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class DDC1872ExampleEntityWithoutOverride
|
||||
{
|
||||
use DDC1872ExampleTrait;
|
||||
}
|
23
tests/Doctrine/Tests/Models/DDC1872/DDC1872ExampleTrait.php
Normal file
23
tests/Doctrine/Tests/Models/DDC1872/DDC1872ExampleTrait.php
Normal 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;
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user