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
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @Entity |
85
|
|
|
* @Table(name="ddc_7561_withdraw_orders") |
86
|
|
|
*/ |
87
|
|
|
class DDC7561WithdrawOrder extends DDC7561AbstractOrder { |
88
|
|
|
/** |
89
|
|
|
* @var DDC7561NonNullableValue |
90
|
|
|
* @Column(type="Doctrine\Tests\ORM\Functional\Ticket\DDC7561NonNullableValueType") |
91
|
|
|
*/ |
92
|
|
|
private $nonNullableValue; |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param int $id |
96
|
|
|
*/ |
97
|
|
|
public function __construct(int $id) |
98
|
|
|
{ |
99
|
|
|
parent::__construct($id); |
100
|
|
|
$this->nonNullableValue = new DDC7561NonNullableValue('pending'); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
class DDC7561NonNullableValueType extends Type |
105
|
|
|
{ |
106
|
|
|
/** |
107
|
|
|
* @return string |
108
|
|
|
*/ |
109
|
|
|
public function convertToDatabaseValue($value, AbstractPlatform $platform): string |
110
|
|
|
{ |
111
|
|
|
return $value; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return DDC7561NonNullableValue |
116
|
|
|
*/ |
117
|
|
|
public function convertToPHPValue($value, AbstractPlatform $platform): DDC7561NonNullableValue |
118
|
|
|
{ |
119
|
|
|
return new DDC7561NonNullableValue($value); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param array $fieldDeclaration |
124
|
|
|
* @param AbstractPlatform $platform |
125
|
|
|
* |
126
|
|
|
* @return string |
127
|
|
|
*/ |
128
|
|
|
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string |
129
|
|
|
{ |
130
|
|
|
return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @return string |
135
|
|
|
*/ |
136
|
|
|
public function getName(): string |
137
|
|
|
{ |
138
|
|
|
return self::class; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
class DDC7561NonNullableValue { |
143
|
|
|
/** |
144
|
|
|
* @var string |
145
|
|
|
*/ |
146
|
|
|
private $value; |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* DDC7561ConfirmationStatus constructor. |
150
|
|
|
* @param string $value |
151
|
|
|
*/ |
152
|
|
|
public function __construct(string $value) |
153
|
|
|
{ |
154
|
|
|
$this->value = $value; |
155
|
|
|
} |
156
|
|
|
} |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.