2013-01-06 17:56:11 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
|
|
|
|
2013-01-06 18:11:30 +04:00
|
|
|
use Doctrine\Tests\Models\CMS\CmsGroup;
|
2013-01-06 17:56:11 +04:00
|
|
|
|
|
|
|
class DDC1734Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
|
|
|
{
|
2013-01-06 18:11:30 +04:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2013-01-06 17:56:11 +04:00
|
|
|
protected function setUp()
|
|
|
|
{
|
2013-01-06 18:11:30 +04:00
|
|
|
$this->useModelSet('cms');
|
2013-01-06 17:56:11 +04:00
|
|
|
parent::setUp();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This test is DDC-1734 minus the serialization, i.e. it works
|
2013-01-06 18:11:30 +04:00
|
|
|
*
|
2013-01-06 17:56:11 +04:00
|
|
|
* @group DDC-1734
|
|
|
|
*/
|
|
|
|
public function testMergeWorksOnNonSerializedProxies()
|
|
|
|
{
|
2013-01-06 18:11:30 +04:00
|
|
|
$group = new CmsGroup();
|
|
|
|
|
|
|
|
$group->setName('Foo');
|
|
|
|
$this->_em->persist($group);
|
2013-01-06 17:56:11 +04:00
|
|
|
$this->_em->flush();
|
|
|
|
$this->_em->clear();
|
2013-01-06 18:11:30 +04:00
|
|
|
|
|
|
|
$proxy = $this->getProxy($group);
|
|
|
|
|
2013-01-06 17:56:11 +04:00
|
|
|
$this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $proxy);
|
2013-01-06 18:11:30 +04:00
|
|
|
$this->assertFalse($proxy->__isInitialized());
|
|
|
|
|
2013-01-06 17:56:11 +04:00
|
|
|
$this->_em->detach($proxy);
|
|
|
|
$this->_em->clear();
|
2013-01-06 18:11:30 +04:00
|
|
|
|
2013-01-06 17:56:11 +04:00
|
|
|
$proxy = $this->_em->merge($proxy);
|
2013-01-06 18:11:30 +04:00
|
|
|
|
|
|
|
$this->assertEquals('Foo', $proxy->getName(), 'The entity is broken');
|
2013-01-06 17:56:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This test reproduces DDC-1734 which is:
|
|
|
|
* - A non-initialized proxy is detached and serialized (the identifier of the proxy is *not* serialized)
|
|
|
|
* - the object is deserialized and merged (to turn into an entity)
|
|
|
|
* - the entity is broken because it has no identifier and no field defined
|
2013-01-06 18:11:30 +04:00
|
|
|
*
|
2013-01-06 17:56:11 +04:00
|
|
|
* @group DDC-1734
|
|
|
|
*/
|
|
|
|
public function testMergeWorksOnSerializedProxies()
|
|
|
|
{
|
2013-01-06 18:11:30 +04:00
|
|
|
$group = new CmsGroup();
|
|
|
|
|
|
|
|
$group->setName('Foo');
|
|
|
|
$this->_em->persist($group);
|
2013-01-06 17:56:11 +04:00
|
|
|
$this->_em->flush();
|
|
|
|
$this->_em->clear();
|
2013-01-06 18:11:30 +04:00
|
|
|
|
|
|
|
$proxy = $this->getProxy($group);
|
|
|
|
|
2013-01-06 17:56:11 +04:00
|
|
|
$this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $proxy);
|
|
|
|
$this->assertFalse($proxy->__isInitialized());
|
2013-01-06 18:11:30 +04:00
|
|
|
|
2013-01-06 17:56:11 +04:00
|
|
|
$this->_em->detach($proxy);
|
|
|
|
$serializedProxy = serialize($proxy);
|
|
|
|
$this->_em->clear();
|
2013-01-06 18:11:30 +04:00
|
|
|
|
|
|
|
$unserializedProxy = $this->_em->merge(unserialize($serializedProxy));
|
|
|
|
$this->assertEquals('Foo', $unserializedProxy->getName(), 'The entity is broken');
|
2013-01-06 17:56:11 +04:00
|
|
|
}
|
|
|
|
|
2013-01-06 18:11:30 +04:00
|
|
|
/**
|
|
|
|
* @param object $object
|
|
|
|
*
|
|
|
|
* @return \Doctrine\Common\Proxy\Proxy
|
|
|
|
*/
|
2013-01-06 17:56:11 +04:00
|
|
|
private function getProxy($object)
|
|
|
|
{
|
|
|
|
$metadataFactory = $this->_em->getMetadataFactory();
|
2013-01-06 18:11:30 +04:00
|
|
|
$className = get_class($object);
|
|
|
|
$identifier = $metadataFactory->getMetadataFor($className)->getIdentifierValues($object);
|
2013-01-06 17:56:11 +04:00
|
|
|
|
2013-01-06 18:11:30 +04:00
|
|
|
return $this->_em->getProxyFactory()->getProxy($className, $identifier);
|
2013-01-06 17:56:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|