|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace MovingImage\Bundle\VMProApiBundle\Tests\EventListener; |
|
6
|
|
|
|
|
7
|
|
|
use MovingImage\Bundle\VMProApiBundle\EventListener\StopwatchListener; |
|
8
|
|
|
use MovingImage\Bundle\VMProApiBundle\Service\Stopwatch; |
|
9
|
|
|
use PHPUnit\Framework\TestCase; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
12
|
|
|
use Symfony\Component\HttpKernel\Event\FilterResponseEvent; |
|
13
|
|
|
use Symfony\Component\HttpKernel\HttpKernel; |
|
14
|
|
|
use Symfony\Component\HttpKernel\HttpKernelInterface; |
|
15
|
|
|
use Symfony\Component\Stopwatch\Stopwatch as SymfonyStopwatch; |
|
16
|
|
|
|
|
17
|
|
|
class StopwatchListenerTest extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @dataProvider dataProviderForTestOnKernelResponse |
|
21
|
|
|
*/ |
|
22
|
|
|
public function testOnKernelResponse(bool $enabled): void |
|
23
|
|
|
{ |
|
24
|
|
|
$stopwatch = new Stopwatch(new SymfonyStopwatch()); |
|
25
|
|
|
$stopwatch->start('test'); |
|
26
|
|
|
$stopwatch->stop('test'); |
|
27
|
|
|
$listener = new StopwatchListener($stopwatch, $enabled); |
|
28
|
|
|
$request = $this->createMock(Request::class); |
|
29
|
|
|
$response = Response::create(); |
|
30
|
|
|
$kernel = $this->createMock(HttpKernel::class); |
|
31
|
|
|
$event = new FilterResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response); |
|
|
|
|
|
|
32
|
|
|
$listener->onKernelResponse($event); |
|
33
|
|
|
|
|
34
|
|
|
if ($enabled) { |
|
35
|
|
|
$this->assertTrue($response->headers->has('X-API-RESPONSE-TEST')); |
|
36
|
|
|
} else { |
|
37
|
|
|
$this->assertFalse($response->headers->has('X-API-RESPONSE-TEST')); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Data provider for testOnKernelResponse. |
|
43
|
|
|
*/ |
|
44
|
|
|
public function dataProviderForTestOnKernelResponse(): array |
|
45
|
|
|
{ |
|
46
|
|
|
return [ |
|
47
|
|
|
[true], |
|
48
|
|
|
[false], |
|
49
|
|
|
]; |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
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: