|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\NotifyPropertyChanged; |
|
6
|
|
|
use Doctrine\Common\PropertyChangedListener; |
|
7
|
|
|
use Doctrine\ORM\Tools\ToolsException; |
|
8
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @group DDC-2230 |
|
12
|
|
|
*/ |
|
13
|
|
|
class DDC2230Test extends OrmFunctionalTestCase |
|
14
|
|
|
{ |
|
15
|
|
|
protected function setUp() |
|
16
|
|
|
{ |
|
17
|
|
|
parent::setUp(); |
|
18
|
|
|
|
|
19
|
|
|
try { |
|
20
|
|
|
$this->_schemaTool->createSchema(array( |
|
21
|
|
|
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2230User'), |
|
22
|
|
|
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2230Address'), |
|
23
|
|
|
)); |
|
24
|
|
|
} catch (ToolsException $e) {} |
|
|
|
|
|
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testNotifyTrackingNotCalledOnUninitializedProxies() |
|
28
|
|
|
{ |
|
29
|
|
|
$insertedUser = new DDC2230User(); |
|
30
|
|
|
$insertedUser->address = new DDC2230Address(); |
|
31
|
|
|
|
|
32
|
|
|
$this->_em->persist($insertedUser); |
|
33
|
|
|
$this->_em->persist($insertedUser->address); |
|
34
|
|
|
$this->_em->flush(); |
|
35
|
|
|
$this->_em->clear(); |
|
36
|
|
|
|
|
37
|
|
|
$user = $this->_em->find(__NAMESPACE__ . '\\DDC2230User', $insertedUser->id); |
|
38
|
|
|
|
|
39
|
|
|
$this->_em->clear(); |
|
40
|
|
|
|
|
41
|
|
|
$mergedUser = $this->_em->merge($user); |
|
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
/* @var $address \Doctrine\Common\Proxy\Proxy */ |
|
44
|
|
|
$address = $mergedUser->address; |
|
45
|
|
|
|
|
46
|
|
|
$this->assertInstanceOf('Doctrine\\ORM\\Proxy\\Proxy', $address); |
|
47
|
|
|
$this->assertFalse($address->__isInitialized()); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testNotifyTrackingCalledOnProxyInitialization() |
|
51
|
|
|
{ |
|
52
|
|
|
$insertedAddress = new DDC2230Address(); |
|
53
|
|
|
|
|
54
|
|
|
$this->_em->persist($insertedAddress); |
|
55
|
|
|
$this->_em->flush(); |
|
56
|
|
|
$this->_em->clear(); |
|
57
|
|
|
|
|
58
|
|
|
$addressProxy = $this->_em->getReference(__NAMESPACE__ . '\\DDC2230Address', $insertedAddress->id); |
|
59
|
|
|
|
|
60
|
|
|
/* @var $addressProxy \Doctrine\Common\Proxy\Proxy|\Doctrine\Tests\ORM\Functional\Ticket\DDC2230Address */ |
|
61
|
|
|
$this->assertFalse($addressProxy->__isInitialized()); |
|
|
|
|
|
|
62
|
|
|
$this->assertNull($addressProxy->listener); |
|
63
|
|
|
|
|
64
|
|
|
$addressProxy->__load(); |
|
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
$this->assertSame($this->_em->getUnitOfWork(), $addressProxy->listener); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** @Entity */ |
|
71
|
|
|
class DDC2230User |
|
72
|
|
|
{ |
|
73
|
|
|
/** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") */ |
|
74
|
|
|
public $id; |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @OneToOne(targetEntity="DDC2230Address") |
|
78
|
|
|
*/ |
|
79
|
|
|
public $address; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @Entity |
|
84
|
|
|
* @ChangeTrackingPolicy("NOTIFY") |
|
85
|
|
|
*/ |
|
86
|
|
|
class DDC2230Address implements NotifyPropertyChanged |
|
87
|
|
|
{ |
|
88
|
|
|
/** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") */ |
|
89
|
|
|
public $id; |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @var \Doctrine\Common\PropertyChangedListener |
|
93
|
|
|
*/ |
|
94
|
|
|
public $listener; |
|
95
|
|
|
|
|
96
|
|
|
/** {@inheritDoc} */ |
|
97
|
|
|
function addPropertyChangedListener(PropertyChangedListener $listener) |
|
|
|
|
|
|
98
|
|
|
{ |
|
99
|
|
|
$this->listener = $listener; |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
|