[2.0] DDC-353 - Fix UnitOfWork::createEntity and StandardPersister::refresh() not marking created Proxy instances as MANAGED like EntityManager::getReference() does
This commit is contained in:
parent
536aca23da
commit
a0fc09855b
4 changed files with 161 additions and 5 deletions
|
@ -489,10 +489,11 @@ class StandardEntityPersister
|
|||
}
|
||||
$newData[$field] = $found;
|
||||
} else {
|
||||
// FIXME: What is happening with subClassees here?
|
||||
$proxy = $this->_em->getProxyFactory()->getProxy($assoc->targetEntityName, $joinColumnValues);
|
||||
$this->_class->reflFields[$field]->setValue($entity, $proxy);
|
||||
$newData[$field] = $proxy;
|
||||
$this->_em->getUnitOfWork()->addToIdentityMap($proxy);
|
||||
$this->_em->getUnitOfWork()->registerManaged($proxy, $joinColumnValues, array());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -1808,8 +1808,7 @@ class UnitOfWork implements PropertyChangedListener
|
|||
$newValue = $assoc->load($entity, null, $this->_em, $associatedId);
|
||||
} else {
|
||||
$newValue = $this->_em->getProxyFactory()->getProxy($assoc->targetEntityName, $associatedId);
|
||||
$this->_entityIdentifiers[spl_object_hash($newValue)] = $associatedId;
|
||||
$this->_identityMap[$targetClass->rootEntityName][$relatedIdHash] = $newValue;
|
||||
$this->registerManaged($newValue, $associatedId, array());
|
||||
}
|
||||
}
|
||||
$this->_originalEntityData[$oid][$field] = $newValue;
|
||||
|
|
154
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC353Test.php
Normal file
154
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC353Test.php
Normal file
|
@ -0,0 +1,154 @@
|
|||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
use Doctrine\ORM\UnitOfWork;
|
||||
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
class DDC353Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
try {
|
||||
$this->_schemaTool->createSchema(array(
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC353File'),
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC353Picture'),
|
||||
));
|
||||
} catch(\Exception $e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function testWorkingCase()
|
||||
{
|
||||
$file = new DDC353File;
|
||||
|
||||
$picture = new DDC353Picture;
|
||||
$picture->setFile($file);
|
||||
|
||||
$em = $this->_em;
|
||||
$em->persist($picture);
|
||||
$em->flush();
|
||||
$em->clear();
|
||||
|
||||
$fileId = $file->getFileId();
|
||||
$this->assertTrue($fileId > 0);
|
||||
|
||||
$file = $em->getReference('Doctrine\Tests\ORM\Functional\Ticket\DDC353File', $fileId);
|
||||
$this->assertEquals(UnitOfWork::STATE_MANAGED, $em->getUnitOfWork()->getEntityState($file), "Reference Proxy should be marked MANAGED.");
|
||||
|
||||
$picture = $em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC353Picture', $picture->getPictureId());
|
||||
$this->assertEquals(UnitOfWork::STATE_MANAGED, $em->getUnitOfWork()->getEntityState($picture->getFile()), "Lazy Proxy should be marked MANAGED.");
|
||||
|
||||
$em->remove($picture);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
public function testFailingCase()
|
||||
{
|
||||
$file = new DDC353File;
|
||||
|
||||
$picture = new DDC353Picture;
|
||||
$picture->setFile($file);
|
||||
|
||||
$em = $this->_em;
|
||||
$em->persist($picture);
|
||||
$em->flush();
|
||||
$em->clear();
|
||||
|
||||
$fileId = $file->getFileId();
|
||||
$pictureId = $picture->getPictureId();
|
||||
|
||||
$this->assertTrue($fileId > 0);
|
||||
|
||||
$picture = $em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC353Picture', $pictureId);
|
||||
$this->assertEquals(UnitOfWork::STATE_MANAGED, $em->getUnitOfWork()->getEntityState($picture->getFile()), "Lazy Proxy should be marked MANAGED.");
|
||||
|
||||
$em->remove($picture);
|
||||
$em->flush();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class DDC353Picture
|
||||
{
|
||||
/**
|
||||
* @Column(name="picture_id", type="integer")
|
||||
* @Id
|
||||
* @GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $pictureId;
|
||||
|
||||
/**
|
||||
* @ManyToOne(targetEntity="DDC353File", cascade={"persist", "remove"})
|
||||
* @JoinColumns({
|
||||
* @JoinColumn(name="file_id", referencedColumnName="file_id")
|
||||
* })
|
||||
*/
|
||||
private $file;
|
||||
|
||||
/**
|
||||
* Get pictureId
|
||||
*/
|
||||
public function getPictureId()
|
||||
{
|
||||
return $this->pictureId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set product
|
||||
*/
|
||||
public function setProduct($value)
|
||||
{
|
||||
$this->product = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get product
|
||||
*/
|
||||
public function getProduct()
|
||||
{
|
||||
return $this->product;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set file
|
||||
*/
|
||||
public function setFile($value)
|
||||
{
|
||||
$this->file = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file
|
||||
*/
|
||||
public function getFile()
|
||||
{
|
||||
return $this->file;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class DDC353File
|
||||
{
|
||||
/**
|
||||
* @Column(name="file_id", type="integer")
|
||||
* @Id
|
||||
* @GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
public $fileId;
|
||||
|
||||
/**
|
||||
* Get fileId
|
||||
*/
|
||||
public function getFileId()
|
||||
{
|
||||
return $this->fileId;
|
||||
}
|
||||
}
|
|
@ -122,14 +122,16 @@ class ObjectHydratorTest extends HydrationTestCase
|
|||
'p__shipping_id' => 42
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
$proxyInstance = new \Doctrine\Tests\Models\ECommerce\ECommerceShipping();
|
||||
|
||||
// mocking the proxy factory
|
||||
$proxyFactory = $this->getMock('Doctrine\ORM\Proxy\ProxyFactory', array('getProxy'), array(), '', false, false, false);
|
||||
$proxyFactory->expects($this->once())
|
||||
->method('getProxy')
|
||||
->with($this->equalTo('Doctrine\Tests\Models\ECommerce\ECommerceShipping'),
|
||||
array('id' => 42))
|
||||
->will($this->returnValue(new \stdClass));
|
||||
->will($this->returnValue($proxyInstance));
|
||||
|
||||
$this->_em->setProxyFactory($proxyFactory);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue