13
13
14
14
use Doctrine \DBAL \ArrayParameterType ;
15
15
use Doctrine \DBAL \Connection ;
16
- use Doctrine \DBAL \Result ;
17
16
use Doctrine \DBAL \Types \GuidType ;
18
17
use Doctrine \DBAL \Types \Type ;
19
18
use Doctrine \ORM \AbstractQuery ;
20
- use Doctrine \ORM \Version ;
19
+ use Doctrine \ORM \Query ;
20
+ use Doctrine \ORM \QueryBuilder ;
21
+ use PHPUnit \Framework \MockObject \MockObject ;
21
22
use PHPUnit \Framework \TestCase ;
22
23
use Symfony \Bridge \Doctrine \Form \ChoiceList \ORMQueryBuilderLoader ;
23
24
use Symfony \Bridge \Doctrine \Tests \DoctrineTestHelper ;
25
+ use Symfony \Bridge \Doctrine \Tests \Fixtures \EmbeddedIdentifierEntity ;
26
+ use Symfony \Bridge \Doctrine \Tests \Fixtures \LegacyQueryMock ;
27
+ use Symfony \Bridge \Doctrine \Tests \Fixtures \SingleIntIdEntity ;
28
+ use Symfony \Bridge \Doctrine \Tests \Fixtures \SingleStringIdEntity ;
24
29
use Symfony \Bridge \Doctrine \Types \UlidType ;
25
30
use Symfony \Bridge \Doctrine \Types \UuidType ;
26
31
use Symfony \Component \Form \Exception \TransformationFailedException ;
@@ -37,21 +42,19 @@ protected function tearDown(): void
37
42
38
43
public function testIdentifierTypeIsStringArray ()
39
44
{
40
- $ this ->checkIdentifierType (' Symfony\Bridge\Doctrine\Tests\Fixtures\ SingleStringIdEntity' , class_exists (ArrayParameterType::class) ? ArrayParameterType::STRING : Connection::PARAM_STR_ARRAY );
45
+ $ this ->checkIdentifierType (SingleStringIdEntity::class , class_exists (ArrayParameterType::class) ? ArrayParameterType::STRING : Connection::PARAM_STR_ARRAY );
41
46
}
42
47
43
48
public function testIdentifierTypeIsIntegerArray ()
44
49
{
45
- $ this ->checkIdentifierType (' Symfony\Bridge\Doctrine\Tests\Fixtures\ SingleIntIdEntity' , class_exists (ArrayParameterType::class) ? ArrayParameterType::INTEGER : Connection::PARAM_INT_ARRAY );
50
+ $ this ->checkIdentifierType (SingleIntIdEntity::class , class_exists (ArrayParameterType::class) ? ArrayParameterType::INTEGER : Connection::PARAM_INT_ARRAY );
46
51
}
47
52
48
- protected function checkIdentifierType ($ classname , $ expectedType )
53
+ protected function checkIdentifierType (string $ classname , $ expectedType )
49
54
{
50
55
$ em = DoctrineTestHelper::createTestEntityManager ();
51
56
52
- $ query = $ this ->getMockBuilder (QueryMock::class)
53
- ->onlyMethods (['setParameter ' , 'getResult ' , 'getSql ' , '_doExecute ' ])
54
- ->getMock ();
57
+ $ query = $ this ->getQueryMock ();
55
58
56
59
$ query
57
60
->method ('getResult ' )
@@ -62,7 +65,7 @@ protected function checkIdentifierType($classname, $expectedType)
62
65
->with ('ORMQueryBuilderLoader_getEntitiesByIds_id ' , [1 , 2 ], $ expectedType )
63
66
->willReturn ($ query );
64
67
65
- $ qb = $ this ->getMockBuilder (\ Doctrine \ ORM \ QueryBuilder::class)
68
+ $ qb = $ this ->getMockBuilder (QueryBuilder::class)
66
69
->setConstructorArgs ([$ em ])
67
70
->onlyMethods (['getQuery ' ])
68
71
->getMock ();
@@ -82,9 +85,7 @@ public function testFilterNonIntegerValues()
82
85
{
83
86
$ em = DoctrineTestHelper::createTestEntityManager ();
84
87
85
- $ query = $ this ->getMockBuilder (QueryMock::class)
86
- ->onlyMethods (['setParameter ' , 'getResult ' , 'getSql ' , '_doExecute ' ])
87
- ->getMock ();
88
+ $ query = $ this ->getQueryMock ();
88
89
89
90
$ query
90
91
->method ('getResult ' )
@@ -95,7 +96,7 @@ public function testFilterNonIntegerValues()
95
96
->with ('ORMQueryBuilderLoader_getEntitiesByIds_id ' , [1 , 2 , 3 , '9223372036854775808 ' ], class_exists (ArrayParameterType::class) ? ArrayParameterType::INTEGER : Connection::PARAM_INT_ARRAY )
96
97
->willReturn ($ query );
97
98
98
- $ qb = $ this ->getMockBuilder (\ Doctrine \ ORM \ QueryBuilder::class)
99
+ $ qb = $ this ->getMockBuilder (QueryBuilder::class)
99
100
->setConstructorArgs ([$ em ])
100
101
->onlyMethods (['getQuery ' ])
101
102
->getMock ();
@@ -118,9 +119,7 @@ public function testFilterEmptyUuids($entityClass)
118
119
{
119
120
$ em = DoctrineTestHelper::createTestEntityManager ();
120
121
121
- $ query = $ this ->getMockBuilder (QueryMock::class)
122
- ->onlyMethods (['setParameter ' , 'getResult ' , 'getSql ' , '_doExecute ' ])
123
- ->getMock ();
122
+ $ query = $ this ->getQueryMock ();
124
123
125
124
$ query
126
125
->method ('getResult ' )
@@ -131,7 +130,7 @@ public function testFilterEmptyUuids($entityClass)
131
130
->with ('ORMQueryBuilderLoader_getEntitiesByIds_id ' , ['71c5fd46-3f16-4abb-bad7-90ac1e654a2d ' , 'b98e8e11-2897-44df-ad24-d2627eb7f499 ' ], class_exists (ArrayParameterType::class) ? ArrayParameterType::STRING : Connection::PARAM_STR_ARRAY )
132
131
->willReturn ($ query );
133
132
134
- $ qb = $ this ->getMockBuilder (\ Doctrine \ ORM \ QueryBuilder::class)
133
+ $ qb = $ this ->getMockBuilder (QueryBuilder::class)
135
134
->setConstructorArgs ([$ em ])
136
135
->onlyMethods (['getQuery ' ])
137
136
->getMock ();
@@ -163,9 +162,7 @@ public function testFilterUid($entityClass)
163
162
164
163
$ em = DoctrineTestHelper::createTestEntityManager ();
165
164
166
- $ query = $ this ->getMockBuilder (QueryMock::class)
167
- ->onlyMethods (['setParameter ' , 'getResult ' , 'getSql ' , '_doExecute ' ])
168
- ->getMock ();
165
+ $ query = $ this ->getQueryMock ();
169
166
170
167
$ query
171
168
->method ('getResult ' )
@@ -176,7 +173,7 @@ public function testFilterUid($entityClass)
176
173
->with ('ORMQueryBuilderLoader_getEntitiesByIds_id ' , [Uuid::fromString ('71c5fd46-3f16-4abb-bad7-90ac1e654a2d ' )->toBinary (), Uuid::fromString ('b98e8e11-2897-44df-ad24-d2627eb7f499 ' )->toBinary ()], class_exists (ArrayParameterType::class) ? ArrayParameterType::STRING : Connection::PARAM_STR_ARRAY )
177
174
->willReturn ($ query );
178
175
179
- $ qb = $ this ->getMockBuilder (\ Doctrine \ ORM \ QueryBuilder::class)
176
+ $ qb = $ this ->getMockBuilder (QueryBuilder::class)
180
177
->setConstructorArgs ([$ em ])
181
178
->onlyMethods (['getQuery ' ])
182
179
->getMock ();
@@ -208,7 +205,7 @@ public function testUidThrowProperException($entityClass)
208
205
209
206
$ em = DoctrineTestHelper::createTestEntityManager ();
210
207
211
- $ qb = $ this ->getMockBuilder (\ Doctrine \ ORM \ QueryBuilder::class)
208
+ $ qb = $ this ->getMockBuilder (QueryBuilder::class)
212
209
->setConstructorArgs ([$ em ])
213
210
->onlyMethods (['getQuery ' ])
214
211
->getMock ();
@@ -229,17 +226,9 @@ public function testUidThrowProperException($entityClass)
229
226
230
227
public function testEmbeddedIdentifierName ()
231
228
{
232
- if (Version::compare ('2.5.0 ' ) > 0 ) {
233
- $ this ->markTestSkipped ('Applicable only for Doctrine >= 2.5.0 ' );
234
-
235
- return ;
236
- }
237
-
238
229
$ em = DoctrineTestHelper::createTestEntityManager ();
239
230
240
- $ query = $ this ->getMockBuilder (QueryMock::class)
241
- ->onlyMethods (['setParameter ' , 'getResult ' , 'getSql ' , '_doExecute ' ])
242
- ->getMock ();
231
+ $ query = $ this ->getQueryMock ();
243
232
244
233
$ query
245
234
->method ('getResult ' )
@@ -250,7 +239,7 @@ public function testEmbeddedIdentifierName()
250
239
->with ('ORMQueryBuilderLoader_getEntitiesByIds_id_value ' , [1 , 2 , 3 ], class_exists (ArrayParameterType::class) ? ArrayParameterType::INTEGER : Connection::PARAM_INT_ARRAY )
251
240
->willReturn ($ query );
252
241
253
- $ qb = $ this ->getMockBuilder (\ Doctrine \ ORM \ QueryBuilder::class)
242
+ $ qb = $ this ->getMockBuilder (QueryBuilder::class)
254
243
->setConstructorArgs ([$ em ])
255
244
->onlyMethods (['getQuery ' ])
256
245
->getMock ();
@@ -259,46 +248,35 @@ public function testEmbeddedIdentifierName()
259
248
->willReturn ($ query );
260
249
261
250
$ qb ->select ('e ' )
262
- ->from (' Symfony\Bridge\Doctrine\Tests\Fixtures\ EmbeddedIdentifierEntity' , 'e ' );
251
+ ->from (EmbeddedIdentifierEntity::class , 'e ' );
263
252
264
253
$ loader = new ORMQueryBuilderLoader ($ qb );
265
254
$ loader ->getEntitiesByIds ('id.value ' , [1 , '' , 2 , 3 , 'foo ' ]);
266
255
}
267
256
268
- public static function provideGuidEntityClasses ()
257
+ public static function provideGuidEntityClasses (): array
269
258
{
270
259
return [
271
260
['Symfony\Bridge\Doctrine\Tests\Fixtures\GuidIdEntity ' ],
272
261
['Symfony\Bridge\Doctrine\Tests\Fixtures\UuidIdEntity ' ],
273
262
];
274
263
}
275
264
276
- public static function provideUidEntityClasses ()
265
+ public static function provideUidEntityClasses (): array
277
266
{
278
267
return [
279
268
['Symfony\Bridge\Doctrine\Tests\Fixtures\UuidIdEntity ' ],
280
269
['Symfony\Bridge\Doctrine\Tests\Fixtures\UlidIdEntity ' ],
281
270
];
282
271
}
283
- }
284
-
285
- class QueryMock extends AbstractQuery
286
- {
287
- public function __construct ()
288
- {
289
- }
290
272
291
273
/**
292
- * @return array|string
274
+ * @return (LegacyQueryMock&MockObject)|(Query&MockObject)
293
275
*/
294
- public function getSQL ()
276
+ private function getQueryMock (): AbstractQuery
295
277
{
296
- }
278
+ $ class = (( new \ ReflectionClass (Query::class))-> isFinal ()) ? LegacyQueryMock::class : Query::class;
297
279
298
- /**
299
- * @return Result|int
300
- */
301
- protected function _doExecute ()
302
- {
280
+ return $ this ->createMock ($ class );
303
281
}
304
282
}
0 commit comments