1
0
mirror of synced 2024-12-14 23:26:04 +03:00
doctrine2/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1734Test.php

89 lines
2.4 KiB
PHP
Raw Normal View History

2013-01-06 17:56:11 +04:00
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\Tests\Models\CMS\CmsGroup;
2013-01-06 17:56:11 +04:00
class DDC1734Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
/**
* {@inheritDoc}
*/
2013-01-06 17:56:11 +04:00
protected function setUp()
{
$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 17:56:11 +04:00
* @group DDC-1734
*/
public function testMergeWorksOnNonSerializedProxies()
{
$group = new CmsGroup();
$group->setName('Foo');
$this->_em->persist($group);
2013-01-06 17:56:11 +04:00
$this->_em->flush();
$this->_em->clear();
$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 17:56:11 +04:00
$this->_em->detach($proxy);
$this->_em->clear();
2013-01-06 17:56:11 +04:00
$proxy = $this->_em->merge($proxy);
$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 17:56:11 +04:00
* @group DDC-1734
*/
public function testMergeWorksOnSerializedProxies()
{
$group = new CmsGroup();
$group->setName('Foo');
$this->_em->persist($group);
2013-01-06 17:56:11 +04:00
$this->_em->flush();
$this->_em->clear();
$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 17:56:11 +04:00
$this->_em->detach($proxy);
$serializedProxy = serialize($proxy);
$this->_em->clear();
$unserializedProxy = $this->_em->merge(unserialize($serializedProxy));
$this->assertEquals('Foo', $unserializedProxy->getName(), 'The entity is broken');
2013-01-06 17:56:11 +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();
$className = get_class($object);
$identifier = $metadataFactory->getMetadataFor($className)->getIdentifierValues($object);
2013-01-06 17:56:11 +04:00
return $this->_em->getProxyFactory()->getProxy($className, $identifier);
2013-01-06 17:56:11 +04:00
}
}