StopwatchListenerTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 7
dl 0
loc 35
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testOnKernelResponse() 0 18 2
A dataProviderForTestOnKernelResponse() 0 7 1
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);
0 ignored issues
show
Documentation introduced by
$kernel is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...el\HttpKernelInterface>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$request is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component\HttpFoundation\Request>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Deprecated Code introduced by
The class Symfony\Component\HttpKe...ent\FilterResponseEvent has been deprecated with message: since Symfony 4.3, use ResponseEvent instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
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