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