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
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @Embeddable |
43
|
|
|
*/ |
44
|
|
|
class GH8031Nested |
45
|
|
|
{ |
46
|
|
|
/** |
47
|
|
|
* @Column(type="integer", name="number", length=6) |
48
|
|
|
* @var int |
49
|
|
|
*/ |
50
|
|
|
protected $number; |
51
|
|
|
|
52
|
|
|
public function __construct(int $number) |
53
|
|
|
{ |
54
|
|
|
$this->number = $number; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function getNumber() : int |
58
|
|
|
{ |
59
|
|
|
return $this->number; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @Embeddable |
65
|
|
|
*/ |
66
|
|
|
class GH8031InvoiceCode extends GH8031AbstractYearSequenceValue |
67
|
|
|
{ |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @Embeddable |
72
|
|
|
*/ |
73
|
|
|
abstract class GH8031AbstractYearSequenceValue |
74
|
|
|
{ |
75
|
|
|
/** |
76
|
|
|
* @Column(type="integer", name="number", length=6) |
77
|
|
|
* @var int |
78
|
|
|
*/ |
79
|
|
|
protected $number; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @Column(type="smallint", name="year", length=4) |
83
|
|
|
* @var int |
84
|
|
|
*/ |
85
|
|
|
protected $year; |
86
|
|
|
|
87
|
|
|
/** @Embedded(class=GH8031Nested::class) */ |
88
|
|
|
protected $nested; |
89
|
|
|
|
90
|
|
|
public function __construct(int $number, int $year, GH8031Nested $nested) |
91
|
|
|
{ |
92
|
|
|
$this->number = $number; |
93
|
|
|
$this->year = $year; |
94
|
|
|
$this->nested = $nested; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function getNumber() : int |
98
|
|
|
{ |
99
|
|
|
return $this->number; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function getYear() : int |
103
|
|
|
{ |
104
|
|
|
return $this->year; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @Entity |
110
|
|
|
*/ |
111
|
|
|
class GH8031Invoice |
112
|
|
|
{ |
113
|
|
|
/** |
114
|
|
|
* @Id |
115
|
|
|
* @GeneratedValue |
116
|
|
|
* @Column(type="integer") |
117
|
|
|
*/ |
118
|
|
|
private $id; |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @Embedded(class=GH8031InvoiceCode::class) |
122
|
|
|
* @var GH8031InvoiceCode |
123
|
|
|
*/ |
124
|
|
|
private $code; |
125
|
|
|
|
126
|
|
|
public function __construct(GH8031InvoiceCode $code) |
127
|
|
|
{ |
128
|
|
|
$this->code = $code; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function getId() |
132
|
|
|
{ |
133
|
|
|
return $this->id; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function getCode() : GH8031InvoiceCode |
137
|
|
|
{ |
138
|
|
|
return $this->code; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|