Passed
Pull Request — master (#11)
by
unknown
07:04
created

StopwatchListenerTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 6
dl 0
loc 38
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testOnKernelResponse() 0 18 2
A dataProviderForTestOnKernelResponse() 0 7 1
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