|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
|
6
|
|
|
use Doctrine\DBAL\Platforms\AbstractPlatform; |
|
7
|
|
|
use Doctrine\DBAL\Types\Type; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @group DDC-7561 |
|
11
|
|
|
*/ |
|
12
|
|
|
class DDC7561Test extends OrmFunctionalTestCase |
|
13
|
|
|
{ |
|
14
|
|
|
public function setUp() |
|
15
|
|
|
{ |
|
16
|
|
|
parent::setUp(); |
|
17
|
|
|
|
|
18
|
|
|
Type::addType( |
|
19
|
|
|
DDC7561NonNullableValueType::class, |
|
20
|
|
|
DDC7561NonNullableValueType::class |
|
21
|
|
|
); |
|
22
|
|
|
|
|
23
|
|
|
$this->_schemaTool->createSchema( |
|
24
|
|
|
[ |
|
25
|
|
|
$this->_em->getClassMetadata(DDC7561AbstractOrder::class), |
|
26
|
|
|
$this->_em->getClassMetadata(DDC7561CardOrder::class), |
|
27
|
|
|
$this->_em->getClassMetadata(DDC7561WithdrawOrder::class), |
|
28
|
|
|
] |
|
29
|
|
|
); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testExpectsDDC7561CardOrderFetching() |
|
33
|
|
|
{ |
|
34
|
|
|
$expectedOrder = new DDC7561CardOrder(1, '1000'); |
|
35
|
|
|
|
|
36
|
|
|
$this->_em->persist($expectedOrder); |
|
37
|
|
|
$this->_em->flush(); |
|
38
|
|
|
$this->_em->clear(); |
|
39
|
|
|
|
|
40
|
|
|
$repository = $this->_em->getRepository(DDC7561AbstractOrder::class); |
|
41
|
|
|
|
|
42
|
|
|
$actualOrder = $repository->find(1); |
|
43
|
|
|
|
|
44
|
|
|
$this->assertEquals($expectedOrder, $actualOrder); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @Entity |
|
50
|
|
|
* @Table(name="ddc_7561_orders") |
|
51
|
|
|
* @InheritanceType("JOINED") |
|
52
|
|
|
* @DiscriminatorColumn(name="type", type="string") |
|
53
|
|
|
* @DiscriminatorMap({ |
|
54
|
|
|
* "card" = "DDC7561CardOrder", |
|
55
|
|
|
* "withdraw" = "DDC7561WithdrawOrder" |
|
56
|
|
|
* }) |
|
57
|
|
|
*/ |
|
58
|
|
|
abstract class DDC7561AbstractOrder { |
|
59
|
|
|
/** |
|
60
|
|
|
* @Id() |
|
61
|
|
|
* @GeneratedValue(strategy="NONE") |
|
62
|
|
|
* @Column(type="integer") |
|
63
|
|
|
* @var int |
|
64
|
|
|
*/ |
|
65
|
|
|
private $id; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param int $id |
|
69
|
|
|
*/ |
|
70
|
|
|
public function __construct(int $id) |
|
71
|
|
|
{ |
|
72
|
|
|
$this->id = $id; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @Entity |
|
78
|
|
|
* @Table(name="ddc_7561_card_orders") |
|
79
|
|
|
*/ |
|
80
|
|
|
class DDC7561CardOrder extends DDC7561AbstractOrder { |
|
81
|
|
|
/** |
|
82
|
|
|
* @var string |
|
83
|
|
|
*/ |
|
84
|
|
|
private $amount; |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param int $id |
|
88
|
|
|
* @param string $amount |
|
89
|
|
|
*/ |
|
90
|
|
|
public function __construct(int $id, string $amount) |
|
91
|
|
|
{ |
|
92
|
|
|
parent::__construct($id); |
|
93
|
|
|
|
|
94
|
|
|
$this->amount = $amount; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @Entity |
|
100
|
|
|
* @Table(name="ddc_7561_withdraw_orders") |
|
101
|
|
|
*/ |
|
102
|
|
|
class DDC7561WithdrawOrder extends DDC7561AbstractOrder { |
|
103
|
|
|
/** |
|
104
|
|
|
* @var DDC7561NonNullableValue |
|
105
|
|
|
* @Column(type="Doctrine\Tests\ORM\Functional\Ticket\DDC7561NonNullableValueType") |
|
106
|
|
|
*/ |
|
107
|
|
|
private $nonNullableValue; |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @param int $id |
|
111
|
|
|
*/ |
|
112
|
|
|
public function __construct(int $id) |
|
113
|
|
|
{ |
|
114
|
|
|
parent::__construct($id); |
|
115
|
|
|
$this->nonNullableValue = new DDC7561NonNullableValue('pending'); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
class DDC7561NonNullableValueType extends Type |
|
120
|
|
|
{ |
|
121
|
|
|
/** |
|
122
|
|
|
* @return string |
|
123
|
|
|
*/ |
|
124
|
|
|
public function convertToDatabaseValue($value, AbstractPlatform $platform): string |
|
125
|
|
|
{ |
|
126
|
|
|
return $value; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @return DDC7561NonNullableValue |
|
131
|
|
|
*/ |
|
132
|
|
|
public function convertToPHPValue($value, AbstractPlatform $platform): DDC7561NonNullableValue |
|
133
|
|
|
{ |
|
134
|
|
|
return new DDC7561NonNullableValue($value); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @param array $fieldDeclaration |
|
139
|
|
|
* @param AbstractPlatform $platform |
|
140
|
|
|
* |
|
141
|
|
|
* @return string |
|
142
|
|
|
*/ |
|
143
|
|
|
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string |
|
144
|
|
|
{ |
|
145
|
|
|
return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @return string |
|
150
|
|
|
*/ |
|
151
|
|
|
public function getName(): string |
|
152
|
|
|
{ |
|
153
|
|
|
return self::class; |
|
154
|
|
|
} |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
class DDC7561NonNullableValue { |
|
158
|
|
|
/** |
|
159
|
|
|
* @var string |
|
160
|
|
|
*/ |
|
161
|
|
|
private $value; |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* DDC7561ConfirmationStatus constructor. |
|
165
|
|
|
* @param string $value |
|
166
|
|
|
*/ |
|
167
|
|
|
public function __construct(string $value) |
|
168
|
|
|
{ |
|
169
|
|
|
$this->value = $value; |
|
170
|
|
|
} |
|
171
|
|
|
} |