Completed
Push — master ( aba493...5356ed )
by Ruud
315:38 queued 305:00
created

unit/EventListener/SessionSecurityListenerTest.php (8 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\AdminBundle\Tests\EventListener;
4
5
use Kunstmaan\AdminBundle\EventListener\SessionSecurityListener;
6
use PHPUnit\Framework\TestCase;
7
use Psr\Log\LoggerInterface;
8
use Symfony\Component\HttpFoundation\HeaderBag;
9
use Symfony\Component\HttpFoundation\Request;
10
use Symfony\Component\HttpFoundation\ServerBag;
11
use Symfony\Component\HttpFoundation\Session\Session;
12
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
13
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
14
use Symfony\Component\HttpKernel\HttpKernelInterface;
15
16
class SessionSecurityListenerTest extends TestCase
17
{
18 View Code Duplication
    public function testOnKernelRequest()
19
    {
20
        $logger = $this->createMock(LoggerInterface::class);
21
        $request = $this->createMock(Request::class);
22
        $request->server = $this->createMock(ServerBag::class);
23
        $request->headers = $this->createMock(HeaderBag::class);
24
25
        $event = $this->createMock(GetResponseEvent::class);
26
        $session = $this->createMock(Session::class);
27
28
        $event->expects($this->any())->method('getRequestType')->willReturn(HttpKernelInterface::MASTER_REQUEST);
29
        $event->expects($this->any())->method('getRequest')->willReturn($request);
30
        $request->expects($this->once())->method('hasSession')->willReturn(true);
31
        $request->expects($this->exactly(2))->method('getSession')->willReturn($session);
32
        $request->server->expects($this->any())->method('get')->will($this->onConsecutiveCalls('Session ip', 'kuma_ua'));
33
        $request->headers->expects($this->any())->method('get')->willReturn('kuma_ua');
34
        $session->expects($this->once())->method('isStarted')->willReturn(true);
35
        $session->expects($this->any())->method('has')->willReturn(true);
36
37
        $listener = new SessionSecurityListener(true, true, $logger);
0 ignored issues
show
$logger is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Psr\Log\LoggerInterface>.

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...
38
        $listener->onKernelRequest($event);
0 ignored issues
show
$event is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...Event\GetResponseEvent>.

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...
39
40
        $event = $this->createMock(GetResponseEvent::class);
41
        $listener->onKernelRequest($event);
0 ignored issues
show
$event is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...Event\GetResponseEvent>.

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...
42
    }
43
44 View Code Duplication
    public function testOnKernelResponse()
45
    {
46
        $logger = $this->createMock(LoggerInterface::class);
47
        $request = $this->createMock(Request::class);
48
        $request->server = $this->createMock(ServerBag::class);
49
        $request->headers = $this->createMock(HeaderBag::class);
50
51
        $event = $this->createMock(FilterResponseEvent::class);
52
        $session = $this->createMock(Session::class);
53
54
        $event->expects($this->any())->method('getRequestType')->willReturn(HttpKernelInterface::MASTER_REQUEST);
55
        $event->expects($this->any())->method('getRequest')->willReturn($request);
56
        $request->expects($this->once())->method('hasSession')->willReturn(true);
57
        $request->expects($this->exactly(2))->method('getSession')->willReturn($session);
58
        $request->server->expects($this->any())->method('get')->will($this->onConsecutiveCalls('Session ip', 'kuma_ua'));
59
        $request->headers->expects($this->any())->method('get')->willReturn('kuma_ua');
60
        $session->expects($this->once())->method('isStarted')->willReturn(true);
61
        $session->expects($this->exactly(2))->method('has')->willReturn(false);
62
63
        $listener = new SessionSecurityListener(true, true, $logger);
0 ignored issues
show
$logger is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Psr\Log\LoggerInterface>.

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...
64
        $listener->onKernelResponse($event);
0 ignored issues
show
$event is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...nt\FilterResponseEvent>.

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...
65
66
        $event = $this->createMock(FilterResponseEvent::class);
67
        $listener->onKernelResponse($event);
0 ignored issues
show
$event is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...nt\FilterResponseEvent>.

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...
68
    }
69
70
    public function testInvalidateSessionWithNoIpSet()
71
    {
72
        $logger = $this->createMock(LoggerInterface::class);
73
        $request = $this->createMock(Request::class);
74
        $request->server = $this->createMock(ServerBag::class);
75
        $request->headers = $this->createMock(HeaderBag::class);
76
77
        $event = $this->createMock(FilterResponseEvent::class);
78
        $session = $this->createMock(Session::class);
79
80
        $event->expects($this->any())->method('getRequestType')->willReturn(HttpKernelInterface::MASTER_REQUEST);
81
        $event->expects($this->any())->method('getRequest')->willReturn($request);
82
        $request->expects($this->once())->method('hasSession')->willReturn(true);
83
        $request->expects($this->exactly(2))->method('getSession')->willReturn($session);
84
        $request->expects($this->once())->method('getClientIp')->willReturn('95.154.243.5');
85
        $request->server->expects($this->any())->method('get')->willReturn('');
86
        $request->headers->expects($this->any())->method('get')->willReturn('kuma_ua');
87
        $session->expects($this->once())->method('isStarted')->willReturn(true);
88
        $session->expects($this->exactly(2))->method('has')->willReturn(false);
89
90
        $listener = new SessionSecurityListener(true, true, $logger);
0 ignored issues
show
$logger is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Psr\Log\LoggerInterface>.

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...
91
        $listener->onKernelResponse($event);
0 ignored issues
show
$event is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...nt\FilterResponseEvent>.

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...
92
    }
93
}
94