13
13
14
14
use FOS \HttpCache \SymfonyCache \CacheEvent ;
15
15
use FOS \HttpCache \SymfonyCache \CacheInvalidation ;
16
- use FOS \HttpCache \SymfonyCache \EventDispatchingHttpCache ;
17
16
use FOS \HttpCache \SymfonyCache \Events ;
18
17
use PHPUnit \Framework \MockObject \MockObject ;
19
18
use PHPUnit \Framework \TestCase ;
@@ -41,14 +40,9 @@ abstract protected function getCacheClass(): string;
41
40
*
42
41
* @param string[] $mockedMethods List of methods to mock
43
42
*/
44
- protected function getHttpCachePartialMock (? array $ mockedMethods = null ): MockObject | CacheInvalidation | EventDispatchingHttpCache
43
+ protected function getHttpCachePartialMock (array $ mockedMethods = [] ): MockObject & CacheInvalidation
45
44
{
46
- $ mock = $ this
47
- ->getMockBuilder ($ this ->getCacheClass ())
48
- ->setMethods ($ mockedMethods )
49
- ->disableOriginalConstructor ()
50
- ->getMock ()
51
- ;
45
+ $ mock = $ this ->createPartialMock ($ this ->getCacheClass (), $ mockedMethods );
52
46
53
47
$ this ->assertInstanceOf (CacheInvalidation::class, $ mock );
54
48
@@ -103,6 +97,7 @@ public function testHandleCalled(): void
103
97
104
98
$ httpCache = $ this ->getHttpCachePartialMock (['lookup ' ]);
105
99
$ testListener = new TestListener ($ this , $ httpCache , $ request );
100
+ $ this ->assertTrue (method_exists ($ httpCache , 'addSubscriber ' ));
106
101
$ httpCache ->addSubscriber ($ testListener );
107
102
$ httpCache
108
103
->method ('lookup ' )
@@ -128,6 +123,7 @@ public function testPreHandleReturnEarly(): void
128
123
$ httpCache = $ this ->getHttpCachePartialMock (['lookup ' ]);
129
124
$ testListener = new TestListener ($ this , $ httpCache , $ request );
130
125
$ testListener ->preHandleResponse = $ response ;
126
+ $ this ->assertTrue (method_exists ($ httpCache , 'addSubscriber ' ));
131
127
$ httpCache ->addSubscriber ($ testListener );
132
128
$ httpCache
133
129
->expects ($ this ->never ())
@@ -154,6 +150,7 @@ public function testPostHandleReturn(): void
154
150
$ httpCache = $ this ->getHttpCachePartialMock (['lookup ' ]);
155
151
$ testListener = new TestListener ($ this , $ httpCache , $ request );
156
152
$ testListener ->postHandleResponse = $ postResponse ;
153
+ $ this ->assertTrue (method_exists ($ httpCache , 'addSubscriber ' ));
157
154
$ httpCache ->addSubscriber ($ testListener );
158
155
$ httpCache
159
156
->method ('lookup ' )
@@ -182,6 +179,7 @@ public function testPostHandleAfterPreHandle(): void
182
179
$ testListener = new TestListener ($ this , $ httpCache , $ request );
183
180
$ testListener ->preHandleResponse = $ preResponse ;
184
181
$ testListener ->postHandleResponse = $ postResponse ;
182
+ $ this ->assertTrue (method_exists ($ httpCache , 'addSubscriber ' ));
185
183
$ httpCache ->addSubscriber ($ testListener );
186
184
$ httpCache
187
185
->expects ($ this ->never ())
@@ -203,6 +201,7 @@ public function testPreStoreCalled(): void
203
201
204
202
$ httpCache = $ this ->getHttpCachePartialMock ();
205
203
$ testListener = new TestListener ($ this , $ httpCache , $ request );
204
+ $ this ->assertTrue (method_exists ($ httpCache , 'addSubscriber ' ));
206
205
$ httpCache ->addSubscriber ($ testListener );
207
206
208
207
$ this ->setStoreMock ($ httpCache , $ request , $ response );
@@ -225,6 +224,7 @@ public function testPreStoreResponse(): void
225
224
$ httpCache = $ this ->getHttpCachePartialMock ();
226
225
$ testListener = new TestListener ($ this , $ httpCache , $ request );
227
226
$ testListener ->preStoreResponse = $ preStoreResponse ;
227
+ $ this ->assertTrue (method_exists ($ httpCache , 'addSubscriber ' ));
228
228
$ httpCache ->addSubscriber ($ testListener );
229
229
230
230
$ this ->setStoreMock ($ httpCache , $ request , $ preStoreResponse );
@@ -247,6 +247,7 @@ public function testPreInvalidateCalled(): void
247
247
$ httpCache = $ this ->getHttpCachePartialMock (['pass ' ]);
248
248
$ testListener = new TestListener ($ this , $ httpCache , $ request );
249
249
$ httpCache ->addSubscriber ($ testListener );
250
+ $ this ->assertTrue (method_exists ($ httpCache , 'addSubscriber ' ));
250
251
$ httpCache
251
252
->method ('pass ' )
252
253
->with ($ request )
@@ -274,6 +275,7 @@ public function testPreInvalidateReturnEarly(): void
274
275
$ testListener = new TestListener ($ this , $ httpCache , $ request );
275
276
$ testListener ->preInvalidateResponse = $ response ;
276
277
$ httpCache ->addSubscriber ($ testListener );
278
+ $ this ->assertTrue (method_exists ($ httpCache , 'addSubscriber ' ));
277
279
$ httpCache
278
280
->expects ($ this ->never ())
279
281
->method ('pass ' )
0 commit comments