2013-02-23 01:44:58 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
|
|
|
|
|
|
|
use Doctrine\Common\NotifyPropertyChanged;
|
|
|
|
use Doctrine\Common\PropertyChangedListener;
|
2016-12-08 18:01:04 +01:00
|
|
|
use Doctrine\Common\Proxy\Proxy;
|
2013-02-23 01:44:58 +01:00
|
|
|
use Doctrine\ORM\Tools\ToolsException;
|
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DDC-2230
|
|
|
|
*/
|
|
|
|
class DDC2230Test extends OrmFunctionalTestCase
|
|
|
|
{
|
2016-05-11 01:55:12 +07:00
|
|
|
protected function setUp()
|
2013-02-23 01:44:58 +01:00
|
|
|
{
|
2016-05-11 01:55:12 +07:00
|
|
|
parent::setUp();
|
2013-02-23 01:44:58 +01:00
|
|
|
|
|
|
|
try {
|
2016-12-07 23:33:41 +01:00
|
|
|
$this->_schemaTool->createSchema(
|
|
|
|
[
|
2016-12-08 18:01:04 +01:00
|
|
|
$this->_em->getClassMetadata(DDC2230User::class),
|
|
|
|
$this->_em->getClassMetadata(DDC2230Address::class),
|
2016-12-07 23:33:41 +01:00
|
|
|
]
|
|
|
|
);
|
2013-02-23 01:44:58 +01:00
|
|
|
} catch (ToolsException $e) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNotifyTrackingNotCalledOnUninitializedProxies()
|
|
|
|
{
|
|
|
|
$insertedUser = new DDC2230User();
|
|
|
|
$insertedUser->address = new DDC2230Address();
|
|
|
|
|
|
|
|
$this->_em->persist($insertedUser);
|
|
|
|
$this->_em->persist($insertedUser->address);
|
|
|
|
$this->_em->flush();
|
|
|
|
$this->_em->clear();
|
|
|
|
|
2016-12-08 18:01:04 +01:00
|
|
|
$user = $this->_em->find(DDC2230User::class, $insertedUser->id);
|
2013-02-23 01:44:58 +01:00
|
|
|
|
|
|
|
$this->_em->clear();
|
|
|
|
|
|
|
|
$mergedUser = $this->_em->merge($user);
|
|
|
|
|
2016-12-08 18:01:04 +01:00
|
|
|
/* @var $address Proxy */
|
2013-02-23 01:44:58 +01:00
|
|
|
$address = $mergedUser->address;
|
|
|
|
|
2016-12-08 18:01:04 +01:00
|
|
|
$this->assertInstanceOf(Proxy::class, $address);
|
2013-02-23 01:44:58 +01:00
|
|
|
$this->assertFalse($address->__isInitialized());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNotifyTrackingCalledOnProxyInitialization()
|
|
|
|
{
|
|
|
|
$insertedAddress = new DDC2230Address();
|
|
|
|
|
|
|
|
$this->_em->persist($insertedAddress);
|
|
|
|
$this->_em->flush();
|
|
|
|
$this->_em->clear();
|
|
|
|
|
2016-12-08 18:01:04 +01:00
|
|
|
$addressProxy = $this->_em->getReference(DDC2230Address::class, $insertedAddress->id);
|
2013-02-23 01:44:58 +01:00
|
|
|
|
2016-12-08 18:01:04 +01:00
|
|
|
/* @var $addressProxy Proxy|\Doctrine\Tests\ORM\Functional\Ticket\DDC2230Address */
|
2013-02-23 01:44:58 +01:00
|
|
|
$this->assertFalse($addressProxy->__isInitialized());
|
|
|
|
$this->assertNull($addressProxy->listener);
|
|
|
|
|
|
|
|
$addressProxy->__load();
|
|
|
|
|
|
|
|
$this->assertSame($this->_em->getUnitOfWork(), $addressProxy->listener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @Entity */
|
|
|
|
class DDC2230User
|
|
|
|
{
|
|
|
|
/** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") */
|
|
|
|
public $id;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @OneToOne(targetEntity="DDC2230Address")
|
|
|
|
*/
|
|
|
|
public $address;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Entity
|
|
|
|
* @ChangeTrackingPolicy("NOTIFY")
|
|
|
|
*/
|
|
|
|
class DDC2230Address implements NotifyPropertyChanged
|
|
|
|
{
|
|
|
|
/** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") */
|
|
|
|
public $id;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Doctrine\Common\PropertyChangedListener
|
|
|
|
*/
|
|
|
|
public $listener;
|
|
|
|
|
|
|
|
/** {@inheritDoc} */
|
|
|
|
function addPropertyChangedListener(PropertyChangedListener $listener)
|
|
|
|
{
|
|
|
|
$this->listener = $listener;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|