1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\Functional\Ticket; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Tools\ToolsException; |
6
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @group #6638 |
10
|
|
|
* @group #6648 |
11
|
|
|
*/ |
12
|
|
|
final class GH6638Test extends OrmFunctionalTestCase |
13
|
|
|
{ |
14
|
|
View Code Duplication |
public function setUp() : void |
15
|
|
|
{ |
16
|
|
|
parent::setUp(); |
17
|
|
|
|
18
|
|
|
try { |
19
|
|
|
$this->_schemaTool->createSchema([ |
20
|
|
|
$this->_em->getClassMetadata(GH6638Customer::class), |
21
|
|
|
$this->_em->getClassMetadata(GH6638Cart::class), |
22
|
|
|
]); |
23
|
|
|
} catch (ToolsException $ignored) { |
|
|
|
|
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
|
27
|
|
View Code Duplication |
public function testFindByDoesNotReHydrateAssociation() : void |
28
|
|
|
{ |
29
|
|
|
$initialCustomer = new GH6638Customer(); |
30
|
|
|
$initialCart = new GH6638Cart(); |
31
|
|
|
|
32
|
|
|
$initialCustomer->cart = $initialCart; |
33
|
|
|
$initialCart->customer = $initialCustomer; |
34
|
|
|
|
35
|
|
|
$this->_em->persist($initialCustomer); |
36
|
|
|
$this->_em->persist($initialCart); |
37
|
|
|
$this->_em->flush(); |
38
|
|
|
$this->_em->clear(); |
39
|
|
|
|
40
|
|
|
$repository = $this->_em->getRepository(GH6638Customer::class); |
41
|
|
|
|
42
|
|
|
$customer = $repository->find($initialCustomer->id); |
43
|
|
|
|
44
|
|
|
self::assertInstanceOf(GH6638Cart::class, $customer->cart); |
45
|
|
|
|
46
|
|
|
$customer->cart = null; |
47
|
|
|
|
48
|
|
|
self::assertNull($customer->cart); |
49
|
|
|
|
50
|
|
|
$repository->findBy(['id' => $initialCustomer->id]); |
51
|
|
|
|
52
|
|
|
self::assertNull($customer->cart); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
View Code Duplication |
public function testFindOneByDoesNotReHydrateAssociation() : void |
56
|
|
|
{ |
57
|
|
|
$initialCustomer = new GH6638Customer(); |
58
|
|
|
$initialCart = new GH6638Cart(); |
59
|
|
|
|
60
|
|
|
$initialCustomer->cart = $initialCart; |
61
|
|
|
$initialCart->customer = $initialCustomer; |
62
|
|
|
|
63
|
|
|
$this->_em->persist($initialCustomer); |
64
|
|
|
$this->_em->persist($initialCart); |
65
|
|
|
$this->_em->flush(); |
66
|
|
|
$this->_em->clear(); |
67
|
|
|
|
68
|
|
|
$repository = $this->_em->getRepository(GH6638Customer::class); |
69
|
|
|
|
70
|
|
|
$customer = $repository->find($initialCustomer->id); |
71
|
|
|
|
72
|
|
|
self::assertInstanceOf(GH6638Cart::class, $customer->cart); |
73
|
|
|
|
74
|
|
|
$customer->cart = null; |
75
|
|
|
|
76
|
|
|
self::assertNull($customer->cart); |
77
|
|
|
|
78
|
|
|
$repository->findOneBy(['id' => $initialCustomer->id]); |
79
|
|
|
|
80
|
|
|
self::assertNull($customer->cart); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** @Entity */ |
85
|
|
|
class GH6638Customer |
86
|
|
|
{ |
87
|
|
|
/** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */ |
88
|
|
|
public $id; |
89
|
|
|
|
90
|
|
|
/** @OneToOne(targetEntity=GH6638Cart::class, mappedBy="customer") */ |
91
|
|
|
public $cart; |
92
|
|
|
|
93
|
|
|
public function __construct() |
94
|
|
|
{ |
95
|
|
|
$this->id = uniqid(self::class, true); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** @Entity */ |
100
|
|
|
class GH6638Cart |
101
|
|
|
{ |
102
|
|
|
/** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */ |
103
|
|
|
public $id; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @OneToOne(targetEntity=GH6638Customer::class, inversedBy="cart") |
107
|
|
|
*/ |
108
|
|
|
public $customer; |
109
|
|
|
|
110
|
|
|
public function __construct() |
111
|
|
|
{ |
112
|
|
|
$this->id = uniqid(self::class, true); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|