1 | <?php |
||
20 | class BypassCacheListenerTest extends TestCase |
||
21 | { |
||
22 | /** |
||
23 | * @var SerializerInterface |
||
24 | */ |
||
25 | private $serializer; |
||
26 | |||
27 | public function setUp(): void |
||
28 | { |
||
29 | $this->serializer = SerializerBuilder::create()->build(); |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * Tests onKernelRequest method. |
||
34 | * |
||
35 | * @dataProvider dataProvider |
||
36 | */ |
||
37 | public function testOnKernelRequest( |
||
38 | ?string $bypassCacheArgument, |
||
39 | array $query, |
||
40 | array $request, |
||
41 | array $attributes, |
||
42 | array $cookies, |
||
43 | bool $isHit |
||
44 | ): void { |
||
45 | $apiClient = $this->getApiClient(); |
||
46 | $listener = new BypassCacheListener($apiClient, $bypassCacheArgument); |
||
47 | $request = new Request($query, $request, $attributes, $cookies); |
||
48 | $kernel = $this->createMock(HttpKernel::class); |
||
49 | |||
50 | $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); |
||
51 | |||
52 | $listener->onKernelRequest($event); |
||
53 | |||
54 | $this->assertIsHit($isHit, $apiClient->getCacheItemPool()); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Creates an ApiClient instance with mocked dependencies |
||
59 | * and ArrayAdapter as cache pool. |
||
60 | */ |
||
61 | private function getApiClient(): ApiClient |
||
62 | { |
||
63 | $client = $this->createMock(ClientInterface::class); |
||
64 | |||
65 | return new ApiClient($client, $this->serializer, new ArrayAdapter()); |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * Asserts that storing an item to the provided pool followed by immediately |
||
70 | * fetching it again from the pool will result in the specified "hit" status. |
||
71 | * ($isHit = true -> expecting a cache hit; $isHit = false -> expecting a cache miss). |
||
72 | */ |
||
73 | private function assertIsHit(bool $isHit, CacheItemPoolInterface $pool): void |
||
80 | |||
81 | /** |
||
82 | * Data provider for testOnKernelRequest. |
||
83 | * Provides various combinations of request arguments and configuration, |
||
84 | * as well as the expected behavior. |
||
85 | */ |
||
86 | public function dataProvider(): array |
||
101 | } |
||
102 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: