1313
1414use Doctrine \DBAL \ArrayParameterType ;
1515use Doctrine \DBAL \Connection ;
16- use Doctrine \DBAL \Result ;
1716use Doctrine \DBAL \Types \GuidType ;
1817use Doctrine \DBAL \Types \Type ;
1918use Doctrine \ORM \AbstractQuery ;
20- use Doctrine \ORM \Version ;
19+ use Doctrine \ORM \Query ;
20+ use Doctrine \ORM \QueryBuilder ;
21+ use PHPUnit \Framework \MockObject \MockObject ;
2122use PHPUnit \Framework \TestCase ;
2223use Symfony \Bridge \Doctrine \Form \ChoiceList \ORMQueryBuilderLoader ;
2324use 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 ;
2429use Symfony \Bridge \Doctrine \Types \UlidType ;
2530use Symfony \Bridge \Doctrine \Types \UuidType ;
2631use Symfony \Component \Form \Exception \TransformationFailedException ;
@@ -37,21 +42,19 @@ protected function tearDown(): void
3742
3843public function testIdentifierTypeIsStringArray ()
3944 {
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 );
4146 }
4247
4348public function testIdentifierTypeIsIntegerArray ()
4449 {
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 );
4651 }
4752
48- protected function checkIdentifierType ($ classname ,$ expectedType )
53+ protected function checkIdentifierType (string $ classname ,$ expectedType )
4954 {
5055$ em = DoctrineTestHelper::createTestEntityManager ();
5156
52- $ query =$ this ->getMockBuilder (QueryMock::class)
53- ->onlyMethods (['setParameter ' ,'getResult ' ,'getSql ' ,'_doExecute ' ])
54- ->getMock ();
57+ $ query =$ this ->getQueryMock ();
5558
5659$ query
5760 ->method ('getResult ' )
@@ -62,7 +65,7 @@ protected function checkIdentifierType($classname, $expectedType)
6265 ->with ('ORMQueryBuilderLoader_getEntitiesByIds_id ' , [1 ,2 ],$ expectedType )
6366 ->willReturn ($ query );
6467
65- $ qb =$ this ->getMockBuilder (\ Doctrine \ ORM \ QueryBuilder::class)
68+ $ qb =$ this ->getMockBuilder (QueryBuilder::class)
6669 ->setConstructorArgs ([$ em ])
6770 ->onlyMethods (['getQuery ' ])
6871 ->getMock ();
@@ -82,9 +85,7 @@ public function testFilterNonIntegerValues()
8285 {
8386$ em = DoctrineTestHelper::createTestEntityManager ();
8487
85- $ query =$ this ->getMockBuilder (QueryMock::class)
86- ->onlyMethods (['setParameter ' ,'getResult ' ,'getSql ' ,'_doExecute ' ])
87- ->getMock ();
88+ $ query =$ this ->getQueryMock ();
8889
8990$ query
9091 ->method ('getResult ' )
@@ -95,7 +96,7 @@ public function testFilterNonIntegerValues()
9596 ->with ('ORMQueryBuilderLoader_getEntitiesByIds_id ' , [1 ,2 ,3 ,'9223372036854775808 ' ],class_exists (ArrayParameterType::class) ? ArrayParameterType::INTEGER : Connection::PARAM_INT_ARRAY )
9697 ->willReturn ($ query );
9798
98- $ qb =$ this ->getMockBuilder (\ Doctrine \ ORM \ QueryBuilder::class)
99+ $ qb =$ this ->getMockBuilder (QueryBuilder::class)
99100 ->setConstructorArgs ([$ em ])
100101 ->onlyMethods (['getQuery ' ])
101102 ->getMock ();
@@ -118,9 +119,7 @@ public function testFilterEmptyUuids($entityClass)
118119 {
119120$ em = DoctrineTestHelper::createTestEntityManager ();
120121
121- $ query =$ this ->getMockBuilder (QueryMock::class)
122- ->onlyMethods (['setParameter ' ,'getResult ' ,'getSql ' ,'_doExecute ' ])
123- ->getMock ();
122+ $ query =$ this ->getQueryMock ();
124123
125124$ query
126125 ->method ('getResult ' )
@@ -131,7 +130,7 @@ public function testFilterEmptyUuids($entityClass)
131130 ->with ('ORMQueryBuilderLoader_getEntitiesByIds_id ' , ['71c5fd46-3f16-4abb-bad7-90ac1e654a2d ' ,'b98e8e11-2897-44df-ad24-d2627eb7f499 ' ],class_exists (ArrayParameterType::class) ? ArrayParameterType::STRING : Connection::PARAM_STR_ARRAY )
132131 ->willReturn ($ query );
133132
134- $ qb =$ this ->getMockBuilder (\ Doctrine \ ORM \ QueryBuilder::class)
133+ $ qb =$ this ->getMockBuilder (QueryBuilder::class)
135134 ->setConstructorArgs ([$ em ])
136135 ->onlyMethods (['getQuery ' ])
137136 ->getMock ();
@@ -163,9 +162,7 @@ public function testFilterUid($entityClass)
163162
164163$ em = DoctrineTestHelper::createTestEntityManager ();
165164
166- $ query =$ this ->getMockBuilder (QueryMock::class)
167- ->onlyMethods (['setParameter ' ,'getResult ' ,'getSql ' ,'_doExecute ' ])
168- ->getMock ();
165+ $ query =$ this ->getQueryMock ();
169166
170167$ query
171168 ->method ('getResult ' )
@@ -176,7 +173,7 @@ public function testFilterUid($entityClass)
176173 ->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 )
177174 ->willReturn ($ query );
178175
179- $ qb =$ this ->getMockBuilder (\ Doctrine \ ORM \ QueryBuilder::class)
176+ $ qb =$ this ->getMockBuilder (QueryBuilder::class)
180177 ->setConstructorArgs ([$ em ])
181178 ->onlyMethods (['getQuery ' ])
182179 ->getMock ();
@@ -208,7 +205,7 @@ public function testUidThrowProperException($entityClass)
208205
209206$ em = DoctrineTestHelper::createTestEntityManager ();
210207
211- $ qb =$ this ->getMockBuilder (\ Doctrine \ ORM \ QueryBuilder::class)
208+ $ qb =$ this ->getMockBuilder (QueryBuilder::class)
212209 ->setConstructorArgs ([$ em ])
213210 ->onlyMethods (['getQuery ' ])
214211 ->getMock ();
@@ -229,17 +226,9 @@ public function testUidThrowProperException($entityClass)
229226
230227public function testEmbeddedIdentifierName ()
231228 {
232- if (Version::compare ('2.5.0 ' ) >0 ) {
233- $ this ->markTestSkipped ('Applicable only for Doctrine >= 2.5.0 ' );
234-
235- return ;
236- }
237-
238229$ em = DoctrineTestHelper::createTestEntityManager ();
239230
240- $ query =$ this ->getMockBuilder (QueryMock::class)
241- ->onlyMethods (['setParameter ' ,'getResult ' ,'getSql ' ,'_doExecute ' ])
242- ->getMock ();
231+ $ query =$ this ->getQueryMock ();
243232
244233$ query
245234 ->method ('getResult ' )
@@ -250,7 +239,7 @@ public function testEmbeddedIdentifierName()
250239 ->with ('ORMQueryBuilderLoader_getEntitiesByIds_id_value ' , [1 ,2 ,3 ],class_exists (ArrayParameterType::class) ? ArrayParameterType::INTEGER : Connection::PARAM_INT_ARRAY )
251240 ->willReturn ($ query );
252241
253- $ qb =$ this ->getMockBuilder (\ Doctrine \ ORM \ QueryBuilder::class)
242+ $ qb =$ this ->getMockBuilder (QueryBuilder::class)
254243 ->setConstructorArgs ([$ em ])
255244 ->onlyMethods (['getQuery ' ])
256245 ->getMock ();
@@ -259,46 +248,35 @@ public function testEmbeddedIdentifierName()
259248 ->willReturn ($ query );
260249
261250$ qb ->select ('e ' )
262- ->from (' Symfony\Bridge\Doctrine\Tests\Fixtures\ EmbeddedIdentifierEntity' ,'e ' );
251+ ->from (EmbeddedIdentifierEntity::class ,'e ' );
263252
264253$ loader =new ORMQueryBuilderLoader ($ qb );
265254$ loader ->getEntitiesByIds ('id.value ' , [1 ,'' ,2 ,3 ,'foo ' ]);
266255 }
267256
268- public static function provideGuidEntityClasses ()
257+ public static function provideGuidEntityClasses (): array
269258 {
270259return [
271260 ['Symfony\Bridge\Doctrine\Tests\Fixtures\GuidIdEntity ' ],
272261 ['Symfony\Bridge\Doctrine\Tests\Fixtures\UuidIdEntity ' ],
273262 ];
274263 }
275264
276- public static function provideUidEntityClasses ()
265+ public static function provideUidEntityClasses (): array
277266 {
278267return [
279268 ['Symfony\Bridge\Doctrine\Tests\Fixtures\UuidIdEntity ' ],
280269 ['Symfony\Bridge\Doctrine\Tests\Fixtures\UlidIdEntity ' ],
281270 ];
282271 }
283- }
284-
285- class QueryMockextends AbstractQuery
286- {
287- public function __construct ()
288- {
289- }
290272
291273/**
292- * @returnarray|string
274+ * @return(LegacyQueryMock&MockObject)|(Query&MockObject)
293275 */
294- public function getSQL ()
276+ private function getQueryMock (): AbstractQuery
295277 {
296- }
278+ $ class = (( new \ ReflectionClass (Query::class))-> isFinal ()) ? LegacyQueryMock::class : Query::class;
297279
298- /**
299- * @return Result|int
300- */
301- protected function _doExecute ()
302- {
280+ return $ this ->createMock ($ class );
303281 }
304282}