@@ -27,9 +27,7 @@ public function testItMakesHydrationCacheProfilesAwareOfTheResultCacheDriver():
2727
2828 $ configuration = new Configuration ();
2929 $ configuration ->setHydrationCache ($ cache );
30- $ entityManager = $ this ->createMock (EntityManagerInterface::class);
31- $ entityManager ->method ('getConfiguration ' )->willReturn ($ configuration );
32- $ query = $ this ->getMockForAbstractClass (AbstractQuery::class, [$ entityManager ]);
30+ $ query = $ this ->createAbstractQuery ($ configuration );
3331 $ cacheProfile = new QueryCacheProfile ();
3432
3533 $ query ->setHydrationCacheProfile ($ cacheProfile );
@@ -45,9 +43,7 @@ public function testItMakesHydrationCacheProfilesAwareOfTheResultCache(): void
4543
4644 $ configuration = new Configuration ();
4745 $ configuration ->setHydrationCache ($ cache );
48- $ entityManager = $ this ->createMock (EntityManagerInterface::class);
49- $ entityManager ->method ('getConfiguration ' )->willReturn ($ configuration );
50- $ query = $ this ->getMockForAbstractClass (AbstractQuery::class, [$ entityManager ]);
46+ $ query = $ this ->createAbstractQuery ($ configuration );
5147 $ cacheProfile = new QueryCacheProfile ();
5248
5349 $ query ->setHydrationCacheProfile ($ cacheProfile );
@@ -61,9 +57,7 @@ public function testItMakesResultCacheProfilesAwareOfTheResultCache(): void
6157
6258 $ configuration = new Configuration ();
6359 $ configuration ->setResultCache ($ cache );
64- $ entityManager = $ this ->createMock (EntityManagerInterface::class);
65- $ entityManager ->method ('getConfiguration ' )->willReturn ($ configuration );
66- $ query = $ this ->getMockForAbstractClass (AbstractQuery::class, [$ entityManager ]);
60+ $ query = $ this ->createAbstractQuery ($ configuration );
6761 $ cacheProfile = new QueryCacheProfile ();
6862
6963 $ query ->setResultCacheProfile ($ cacheProfile );
@@ -74,9 +68,7 @@ public function testItMakesResultCacheProfilesAwareOfTheResultCache(): void
7468 /** @dataProvider provideSettersWithDeprecatedDefault */
7569 public function testCallingSettersWithoutArgumentsIsDeprecated (string $ setter ): void
7670 {
77- $ entityManager = $ this ->createMock (EntityManagerInterface::class);
78- $ entityManager ->method ('getConfiguration ' )->willReturn (new Configuration ());
79- $ query = $ this ->getMockForAbstractClass (AbstractQuery::class, [$ entityManager ]);
71+ $ query = $ this ->createAbstractQuery (new Configuration ());
8072
8173 $ this ->expectDeprecationWithIdentifier ('https://github.com/doctrine/orm/pull/9791 ' );
8274 $ query ->$ setter ();
@@ -95,10 +87,7 @@ public static function provideSettersWithDeprecatedDefault(): array
9587 public function testSettingTheResultCacheIsPossibleWithoutCallingDeprecatedMethods (): void
9688 {
9789 $ cache = $ this ->createMock (CacheItemPoolInterface::class);
98-
99- $ entityManager = $ this ->createMock (EntityManagerInterface::class);
100- $ entityManager ->method ('getConfiguration ' )->willReturn (new Configuration ());
101- $ query = $ this ->getMockForAbstractClass (AbstractQuery::class, [$ entityManager ]);
90+ $ query = $ this ->createAbstractQuery (new Configuration ());
10291
10392 $ query ->setResultCache ($ cache );
10493 self ::assertSame ($ cache , CacheAdapter::wrap ($ query ->getResultCacheDriver ()));
@@ -107,13 +96,27 @@ public function testSettingTheResultCacheIsPossibleWithoutCallingDeprecatedMetho
10796
10897 public function testSettingTheFetchModeToRandomIntegersIsDeprecated (): void
10998 {
110- $ query = $ this ->getMockForAbstractClass (
111- AbstractQuery::class,
112- [],
113- '' ,
114- false // no need to call the constructor
115- );
99+ $ query = $ this ->createAbstractQuery (new Configuration ());
100+
116101 $ this ->expectDeprecationWithIdentifier ('https://github.com/doctrine/orm/pull/9777 ' );
117102 $ query ->setFetchMode (stdClass::class, 'foo ' , 42 );
118103 }
104+
105+ private function createAbstractQuery (Configuration $ configuration ): AbstractQuery
106+ {
107+ $ entityManager = $ this ->createMock (EntityManagerInterface::class);
108+ $ entityManager ->method ('getConfiguration ' )->willReturn ($ configuration );
109+
110+ return new class ($ entityManager ) extends AbstractQuery {
111+ public function getSQL (): string
112+ {
113+ return '' ;
114+ }
115+
116+ protected function _doExecute (): int
117+ {
118+ return 0 ;
119+ }
120+ };
121+ }
119122}
0 commit comments