@@ -27,9 +27,7 @@ public function testItMakesHydrationCacheProfilesAwareOfTheResultCacheDriver():
27
27
28
28
$ configuration = new Configuration ();
29
29
$ 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 );
33
31
$ cacheProfile = new QueryCacheProfile ();
34
32
35
33
$ query ->setHydrationCacheProfile ($ cacheProfile );
@@ -45,9 +43,7 @@ public function testItMakesHydrationCacheProfilesAwareOfTheResultCache(): void
45
43
46
44
$ configuration = new Configuration ();
47
45
$ 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 );
51
47
$ cacheProfile = new QueryCacheProfile ();
52
48
53
49
$ query ->setHydrationCacheProfile ($ cacheProfile );
@@ -61,9 +57,7 @@ public function testItMakesResultCacheProfilesAwareOfTheResultCache(): void
61
57
62
58
$ configuration = new Configuration ();
63
59
$ 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 );
67
61
$ cacheProfile = new QueryCacheProfile ();
68
62
69
63
$ query ->setResultCacheProfile ($ cacheProfile );
@@ -74,9 +68,7 @@ public function testItMakesResultCacheProfilesAwareOfTheResultCache(): void
74
68
/** @dataProvider provideSettersWithDeprecatedDefault */
75
69
public function testCallingSettersWithoutArgumentsIsDeprecated (string $ setter ): void
76
70
{
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 ());
80
72
81
73
$ this ->expectDeprecationWithIdentifier ('https://github.com/doctrine/orm/pull/9791 ' );
82
74
$ query ->$ setter ();
@@ -95,10 +87,7 @@ public static function provideSettersWithDeprecatedDefault(): array
95
87
public function testSettingTheResultCacheIsPossibleWithoutCallingDeprecatedMethods (): void
96
88
{
97
89
$ 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 ());
102
91
103
92
$ query ->setResultCache ($ cache );
104
93
self ::assertSame ($ cache , CacheAdapter::wrap ($ query ->getResultCacheDriver ()));
@@ -107,13 +96,27 @@ public function testSettingTheResultCacheIsPossibleWithoutCallingDeprecatedMetho
107
96
108
97
public function testSettingTheFetchModeToRandomIntegersIsDeprecated (): void
109
98
{
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
+
116
101
$ this ->expectDeprecationWithIdentifier ('https://github.com/doctrine/orm/pull/9777 ' );
117
102
$ query ->setFetchMode (stdClass::class, 'foo ' , 42 );
118
103
}
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
+ }
119
122
}
0 commit comments