1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
6
|
|
|
|
7
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
8
|
|
|
|
9
|
|
|
class GH8031Test extends OrmFunctionalTestCase |
10
|
|
|
{ |
11
|
|
|
protected function setUp() |
12
|
|
|
{ |
13
|
|
|
parent::setUp(); |
14
|
|
|
|
15
|
|
|
$this->setUpEntitySchema([ |
16
|
|
|
GH8031Invoice::class, |
17
|
|
|
]); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function testEntityIsFetched() |
21
|
|
|
{ |
22
|
|
|
$entity = new GH8031Invoice(new GH8031InvoiceCode(1, 2020, new GH8031Nested(10))); |
23
|
|
|
$this->_em->persist($entity); |
24
|
|
|
$this->_em->flush(); |
25
|
|
|
$this->_em->clear(); |
26
|
|
|
|
27
|
|
|
/** @var GH8031Invoice $fetched */ |
28
|
|
|
$fetched = $this->_em->find(GH8031Invoice::class, $entity->getId()); |
29
|
|
|
$this->assertInstanceOf(GH8031Invoice::class, $fetched); |
30
|
|
|
$this->assertSame(1, $fetched->getCode()->getNumber()); |
31
|
|
|
$this->assertSame(2020, $fetched->getCode()->getYear()); |
32
|
|
|
|
33
|
|
|
$this->_em->clear(); |
34
|
|
|
$this->assertCount( |
35
|
|
|
1, |
36
|
|
|
$this->_em->getRepository(GH8031Invoice::class)->findBy([], ['code.number' => 'ASC']) |
37
|
|
|
); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testEmbeddableWithAssociationNotAllowed() |
41
|
|
|
{ |
42
|
|
|
$cm = $this->_em->getClassMetadata(GH8031EmbeddableWithAssociation::class); |
43
|
|
|
|
44
|
|
|
$this->assertArrayHasKey('invoice', $cm->associationMappings); |
45
|
|
|
|
46
|
|
|
$cm = $this->_em->getClassMetadata(GH8031Invoice::class); |
47
|
|
|
|
48
|
|
|
$this->assertCount(0, $cm->associationMappings); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @Embeddable |
54
|
|
|
*/ |
55
|
|
|
class GH8031EmbeddableWithAssociation |
56
|
|
|
{ |
57
|
|
|
/** @ManyToOne(targetEntity=GH8031Invoice::class) */ |
58
|
|
|
public $invoice; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @Embeddable |
63
|
|
|
*/ |
64
|
|
|
class GH8031Nested |
65
|
|
|
{ |
66
|
|
|
/** |
67
|
|
|
* @Column(type="integer", name="number", length=6) |
68
|
|
|
* @var int |
69
|
|
|
*/ |
70
|
|
|
protected $number; |
71
|
|
|
|
72
|
|
|
public function __construct(int $number) |
73
|
|
|
{ |
74
|
|
|
$this->number = $number; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function getNumber() : int |
78
|
|
|
{ |
79
|
|
|
return $this->number; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @Embeddable |
85
|
|
|
*/ |
86
|
|
|
class GH8031InvoiceCode extends GH8031AbstractYearSequenceValue |
87
|
|
|
{ |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @Embeddable |
92
|
|
|
*/ |
93
|
|
|
abstract class GH8031AbstractYearSequenceValue |
94
|
|
|
{ |
95
|
|
|
/** |
96
|
|
|
* @Column(type="integer", name="number", length=6) |
97
|
|
|
* @var int |
98
|
|
|
*/ |
99
|
|
|
protected $number; |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @Column(type="smallint", name="year", length=4) |
103
|
|
|
* @var int |
104
|
|
|
*/ |
105
|
|
|
protected $year; |
106
|
|
|
|
107
|
|
|
/** @Embedded(class=GH8031Nested::class) */ |
108
|
|
|
protected $nested; |
109
|
|
|
|
110
|
|
|
public function __construct(int $number, int $year, GH8031Nested $nested) |
111
|
|
|
{ |
112
|
|
|
$this->number = $number; |
113
|
|
|
$this->year = $year; |
114
|
|
|
$this->nested = $nested; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function getNumber() : int |
118
|
|
|
{ |
119
|
|
|
return $this->number; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function getYear() : int |
123
|
|
|
{ |
124
|
|
|
return $this->year; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @Entity |
130
|
|
|
*/ |
131
|
|
|
class GH8031Invoice |
132
|
|
|
{ |
133
|
|
|
/** |
134
|
|
|
* @Id |
135
|
|
|
* @GeneratedValue |
136
|
|
|
* @Column(type="integer") |
137
|
|
|
*/ |
138
|
|
|
private $id; |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @Embedded(class=GH8031InvoiceCode::class) |
142
|
|
|
* @var GH8031InvoiceCode |
143
|
|
|
*/ |
144
|
|
|
private $code; |
145
|
|
|
|
146
|
|
|
/** @Embedded(class=GH8031EmbeddableWithAssociation::class) */ |
147
|
|
|
private $embeddedAssoc; |
|
|
|
|
148
|
|
|
|
149
|
|
|
public function __construct(GH8031InvoiceCode $code) |
150
|
|
|
{ |
151
|
|
|
$this->code = $code; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function getId() |
155
|
|
|
{ |
156
|
|
|
return $this->id; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function getCode() : GH8031InvoiceCode |
160
|
|
|
{ |
161
|
|
|
return $this->code; |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|