diff --git a/lib/Doctrine/ORM/Mapping/ReflectionEmbeddedProperty.php b/lib/Doctrine/ORM/Mapping/ReflectionEmbeddedProperty.php index 0163ebb89..bad10f2b4 100644 --- a/lib/Doctrine/ORM/Mapping/ReflectionEmbeddedProperty.php +++ b/lib/Doctrine/ORM/Mapping/ReflectionEmbeddedProperty.php @@ -48,6 +48,11 @@ class ReflectionEmbeddedProperty extends ReflectionProperty */ private $instantiator; + /** + * @var string + */ + private $reflectionClass; + /** * @param ReflectionProperty $parentProperty * @param ReflectionProperty $childProperty @@ -57,6 +62,7 @@ class ReflectionEmbeddedProperty extends ReflectionProperty { $this->parentProperty = $parentProperty; $this->childProperty = $childProperty; + $this->reflectionClass = $class; 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->reflectionClass); $this->parentProperty->setValue($object, $embeddedObject); } diff --git a/tests/Doctrine/Tests/Models/Mapping/AbstractEmbedded.php b/tests/Doctrine/Tests/Models/Mapping/AbstractEmbedded.php new file mode 100644 index 000000000..01bb568e1 --- /dev/null +++ b/tests/Doctrine/Tests/Models/Mapping/AbstractEmbedded.php @@ -0,0 +1,33 @@ +foo; + } + + /** + * @param $foo + * @return $this + */ + public function setFoo($foo) + { + $this->foo = $foo; + return $this; + } +} diff --git a/tests/Doctrine/Tests/Models/Mapping/Embedded.php b/tests/Doctrine/Tests/Models/Mapping/Embedded.php new file mode 100644 index 000000000..2509df592 --- /dev/null +++ b/tests/Doctrine/Tests/Models/Mapping/Embedded.php @@ -0,0 +1,33 @@ +bar; + } + + /** + * @param $bar + * @return $this + */ + public function setBar($bar) + { + $this->bar = $bar; + return $this; + } +} diff --git a/tests/Doctrine/Tests/Models/Mapping/Entity.php b/tests/Doctrine/Tests/Models/Mapping/Entity.php new file mode 100644 index 000000000..8dcf86f44 --- /dev/null +++ b/tests/Doctrine/Tests/Models/Mapping/Entity.php @@ -0,0 +1,33 @@ +embedded; + } + + /** + * @param Embedded $embedded + * @return $this + */ + public function setEmbedded($embedded) + { + $this->embedded = $embedded; + return $this; + } +} diff --git a/tests/Doctrine/Tests/ORM/Mapping/ReflectionEmbeddedPropertyTest.php b/tests/Doctrine/Tests/ORM/Mapping/ReflectionEmbeddedPropertyTest.php index 8a67efdf3..0553f6e4c 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ReflectionEmbeddedPropertyTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ReflectionEmbeddedPropertyTest.php @@ -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; /** @@ -66,6 +67,24 @@ class ReflectionEmbeddedPropertyTest extends \PHPUnit_Framework_TestCase )); } + public function testSetValueCanInstantiateObject() + { + $entity = new Entity(); + $parentProperty = new ReflectionProperty('Doctrine\Tests\Models\Mapping\Entity', 'embedded'); + $parentProperty->setAccessible(true); + $childProperty = new ReflectionProperty('Doctrine\Tests\Models\Mapping\Embedded', 'foo'); + $childProperty->setAccessible(true); + $embeddedPropertyReflection = new ReflectionEmbeddedProperty( + $parentProperty, + $childProperty, + 'Doctrine\Tests\Models\Mapping\Embedded' + ); + + $embeddedPropertyReflection->setValue($entity, 4); + + $this->assertEquals(4, $entity->getEmbedded()->getFoo()); + } + /** * Data provider *