1
0
mirror of synced 2025-02-20 22:23:14 +03:00

Merge branch 'hotfix/#1213-DDC-3437-reflection-embeddable-with-abstract-embeddable-ancestor'

Close #1213
This commit is contained in:
Marco Pivetta 2014-12-08 01:22:31 +01:00
commit 9509bec79a
4 changed files with 77 additions and 26 deletions

View File

@ -34,15 +34,20 @@ use ReflectionProperty;
class ReflectionEmbeddedProperty extends ReflectionProperty
{
/**
* @var ReflectionProperty
* @var ReflectionProperty reflection property of the class where the embedded object has to be put
*/
private $parentProperty;
/**
* @var ReflectionProperty
* @var ReflectionProperty reflection property of the embedded object
*/
private $childProperty;
/**
* @var string name of the embedded class to be eventually instantiated
*/
private $embeddedClass;
/**
* @var Instantiator|null
*/
@ -51,12 +56,13 @@ class ReflectionEmbeddedProperty extends ReflectionProperty
/**
* @param ReflectionProperty $parentProperty
* @param ReflectionProperty $childProperty
* @param string $class
* @param string $embeddedClass
*/
public function __construct(ReflectionProperty $parentProperty, ReflectionProperty $childProperty, $class)
public function __construct(ReflectionProperty $parentProperty, ReflectionProperty $childProperty, $embeddedClass)
{
$this->parentProperty = $parentProperty;
$this->childProperty = $childProperty;
$this->parentProperty = $parentProperty;
$this->childProperty = $childProperty;
$this->embeddedClass = (string) $embeddedClass;
parent::__construct($childProperty->getDeclaringClass()->getName(), $childProperty->getName());
}
@ -85,7 +91,7 @@ class ReflectionEmbeddedProperty extends ReflectionProperty
if (null === $embeddedObject) {
$this->instantiator = $this->instantiator ?: new Instantiator();
$embeddedObject = $this->instantiator->instantiate($this->class);
$embeddedObject = $this->instantiator->instantiate($this->embeddedClass);
$this->parentProperty->setValue($object, $embeddedObject);
}

View File

@ -0,0 +1,11 @@
<?php
namespace Doctrine\Tests\Models\Reflection;
/**
* A test asset used to check that embeddables support properties defined in abstract classes
*/
abstract class AbstractEmbeddable
{
private $propertyInAbstractClass;
}

View File

@ -0,0 +1,11 @@
<?php
namespace Doctrine\Tests\Models\Reflection;
/**
* A test asset used to check that embeddables support properties defined in abstract classes
*/
class ConcreteEmbeddable extends AbstractEmbeddable
{
private $propertyInConcreteClass;
}

View File

@ -4,6 +4,7 @@ namespace Doctrine\Tests\ORM\Mapping;
use Doctrine\Instantiator\Instantiator;
use Doctrine\ORM\Mapping\ReflectionEmbeddedProperty;
use Doctrine\Tests\Models\Mapping\Entity;
use ReflectionProperty;
/**
@ -14,20 +15,18 @@ use ReflectionProperty;
class ReflectionEmbeddedPropertyTest extends \PHPUnit_Framework_TestCase
{
/**
* @param ReflectionProperty $parentProperty
* @param ReflectionProperty $childProperty
* @param ReflectionProperty $parentProperty property of the embeddable/entity where to write the embeddable to
* @param ReflectionProperty $childProperty property of the embeddable class where to write values to
* @param string $embeddableClass name of the embeddable class to be instantiated
*
* @dataProvider getTestedReflectionProperties
*/
public function testCanSetAndGetEmbeddedProperty(
ReflectionProperty $parentProperty,
ReflectionProperty $childProperty
ReflectionProperty $childProperty,
$embeddableClass
) {
$embeddedPropertyReflection = new ReflectionEmbeddedProperty(
$parentProperty,
$childProperty,
$childProperty->getDeclaringClass()->getName()
);
$embeddedPropertyReflection = new ReflectionEmbeddedProperty($parentProperty, $childProperty, $embeddableClass);
$instantiator = new Instantiator();
@ -43,21 +42,18 @@ class ReflectionEmbeddedPropertyTest extends \PHPUnit_Framework_TestCase
}
/**
* @param ReflectionProperty $parentProperty
* @param ReflectionProperty $childProperty
* @param ReflectionProperty $parentProperty property of the embeddable/entity where to write the embeddable to
* @param ReflectionProperty $childProperty property of the embeddable class where to write values to
* @param string $embeddableClass name of the embeddable class to be instantiated
*
* @dataProvider getTestedReflectionProperties
*/
public function testWillSkipReadingPropertiesFromNullEmbeddable(
ReflectionProperty $parentProperty,
ReflectionProperty $childProperty
)
{
$embeddedPropertyReflection = new ReflectionEmbeddedProperty(
$parentProperty,
$childProperty,
$childProperty->getDeclaringClass()->getName()
);
ReflectionProperty $childProperty,
$embeddableClass
) {
$embeddedPropertyReflection = new ReflectionEmbeddedProperty($parentProperty, $childProperty, $embeddableClass);
$instantiator = new Instantiator();
@ -69,7 +65,7 @@ class ReflectionEmbeddedPropertyTest extends \PHPUnit_Framework_TestCase
/**
* Data provider
*
* @return ReflectionProperty[][]
* @return ReflectionProperty[][]|string[][]
*/
public function getTestedReflectionProperties()
{
@ -83,6 +79,30 @@ class ReflectionEmbeddedPropertyTest extends \PHPUnit_Framework_TestCase
'Doctrine\\Tests\\Models\\Generic\\BooleanModel',
'id'
),
'Doctrine\\Tests\\Models\\Generic\\BooleanModel'
),
// reflection on embeddables that have properties defined in abstract ancestors:
array(
$this->getReflectionProperty(
'Doctrine\\Tests\\Models\\Generic\\BooleanModel',
'id'
),
$this->getReflectionProperty(
'Doctrine\\Tests\\Models\\Reflection\\AbstractEmbeddable',
'propertyInAbstractClass'
),
'Doctrine\\Tests\\Models\\Reflection\\ConcreteEmbeddable'
),
array(
$this->getReflectionProperty(
'Doctrine\\Tests\\Models\\Generic\\BooleanModel',
'id'
),
$this->getReflectionProperty(
'Doctrine\\Tests\\Models\\Reflection\\ConcreteEmbeddable',
'propertyInConcreteClass'
),
'Doctrine\\Tests\\Models\\Reflection\\ConcreteEmbeddable'
),
// reflection on classes extending internal PHP classes:
array(
@ -94,6 +114,7 @@ class ReflectionEmbeddedPropertyTest extends \PHPUnit_Framework_TestCase
'Doctrine\\Tests\\Models\\Reflection\\ArrayObjectExtendingClass',
'privateProperty'
),
'Doctrine\\Tests\\Models\\Reflection\\ArrayObjectExtendingClass'
),
array(
$this->getReflectionProperty(
@ -104,6 +125,7 @@ class ReflectionEmbeddedPropertyTest extends \PHPUnit_Framework_TestCase
'Doctrine\\Tests\\Models\\Reflection\\ArrayObjectExtendingClass',
'protectedProperty'
),
'Doctrine\\Tests\\Models\\Reflection\\ArrayObjectExtendingClass'
),
array(
$this->getReflectionProperty(
@ -114,6 +136,7 @@ class ReflectionEmbeddedPropertyTest extends \PHPUnit_Framework_TestCase
'Doctrine\\Tests\\Models\\Reflection\\ArrayObjectExtendingClass',
'publicProperty'
),
'Doctrine\\Tests\\Models\\Reflection\\ArrayObjectExtendingClass'
),
);
}