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 PHPUnit_Framework_TestCase |
||
17 | { |
||
18 | View Code Duplication | public function testOnKernelRequest() |
|
0 ignored issues
–
show
|
|||
19 | { |
||
20 | $logger = $this->createMock(LoggerInterface::class); |
||
21 | $request = $this->createMock(Request::class); |
||
22 | $request->server = $this->createMock(ServerBag::class); |
||
0 ignored issues
–
show
Accessing
server on the interface PHPUnit_Framework_MockObject_MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
Loading history...
|
|||
23 | $request->headers = $this->createMock(HeaderBag::class); |
||
0 ignored issues
–
show
Accessing
headers on the interface PHPUnit_Framework_MockObject_MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
Loading history...
|
|||
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')); |
||
0 ignored issues
–
show
Accessing
server on the interface PHPUnit_Framework_MockObject_MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
Loading history...
|
|||
33 | $request->headers->expects($this->any())->method('get')->willReturn('kuma_ua'); |
||
0 ignored issues
–
show
Accessing
headers on the interface PHPUnit_Framework_MockObject_MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
Loading history...
|
|||
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); |
||
38 | $listener->onKernelRequest($event); |
||
39 | |||
40 | $event = $this->createMock(GetResponseEvent::class); |
||
41 | $listener->onKernelRequest($event); |
||
42 | } |
||
43 | |||
44 | |||
45 | View Code Duplication | public function testOnKernelResponse() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
46 | { |
||
47 | $logger = $this->createMock(LoggerInterface::class); |
||
48 | $request = $this->createMock(Request::class); |
||
49 | $request->server = $this->createMock(ServerBag::class); |
||
0 ignored issues
–
show
Accessing
server on the interface PHPUnit_Framework_MockObject_MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
Loading history...
|
|||
50 | $request->headers = $this->createMock(HeaderBag::class); |
||
0 ignored issues
–
show
Accessing
headers on the interface PHPUnit_Framework_MockObject_MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
Loading history...
|
|||
51 | |||
52 | $event = $this->createMock(FilterResponseEvent::class); |
||
53 | $session = $this->createMock(Session::class); |
||
54 | |||
55 | $event->expects($this->any())->method('getRequestType')->willReturn(HttpKernelInterface::MASTER_REQUEST); |
||
56 | $event->expects($this->any())->method('getRequest')->willReturn($request); |
||
57 | $request->expects($this->once())->method('hasSession')->willReturn(true); |
||
58 | $request->expects($this->exactly(2))->method('getSession')->willReturn($session); |
||
59 | $request->server->expects($this->any())->method('get')->will($this->onConsecutiveCalls('Session ip', 'kuma_ua')); |
||
0 ignored issues
–
show
Accessing
server on the interface PHPUnit_Framework_MockObject_MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
Loading history...
|
|||
60 | $request->headers->expects($this->any())->method('get')->willReturn('kuma_ua'); |
||
0 ignored issues
–
show
Accessing
headers on the interface PHPUnit_Framework_MockObject_MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
Loading history...
|
|||
61 | $session->expects($this->once())->method('isStarted')->willReturn(true); |
||
62 | $session->expects($this->exactly(2))->method('has')->willReturn(false); |
||
63 | |||
64 | $listener = new SessionSecurityListener(true, true, $logger); |
||
65 | $listener->onKernelResponse($event); |
||
66 | |||
67 | $event = $this->createMock(FilterResponseEvent::class); |
||
68 | $listener->onKernelResponse($event); |
||
69 | } |
||
70 | |||
71 | |||
72 | public function testInvalidateSessionWithNoIpSet() |
||
73 | { |
||
74 | $logger = $this->createMock(LoggerInterface::class); |
||
75 | $request = $this->createMock(Request::class); |
||
76 | $request->server = $this->createMock(ServerBag::class); |
||
0 ignored issues
–
show
Accessing
server on the interface PHPUnit_Framework_MockObject_MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
Loading history...
|
|||
77 | $request->headers = $this->createMock(HeaderBag::class); |
||
0 ignored issues
–
show
Accessing
headers on the interface PHPUnit_Framework_MockObject_MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
Loading history...
|
|||
78 | |||
79 | $event = $this->createMock(FilterResponseEvent::class); |
||
80 | $session = $this->createMock(Session::class); |
||
81 | |||
82 | $event->expects($this->any())->method('getRequestType')->willReturn(HttpKernelInterface::MASTER_REQUEST); |
||
83 | $event->expects($this->any())->method('getRequest')->willReturn($request); |
||
84 | $request->expects($this->once())->method('hasSession')->willReturn(true); |
||
85 | $request->expects($this->exactly(2))->method('getSession')->willReturn($session); |
||
86 | $request->expects($this->once())->method('getClientIp')->willReturn('95.154.243.5'); |
||
87 | $request->server->expects($this->any())->method('get')->willReturn(''); |
||
0 ignored issues
–
show
Accessing
server on the interface PHPUnit_Framework_MockObject_MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
Loading history...
|
|||
88 | $request->headers->expects($this->any())->method('get')->willReturn('kuma_ua'); |
||
0 ignored issues
–
show
Accessing
headers on the interface PHPUnit_Framework_MockObject_MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
Loading history...
|
|||
89 | $session->expects($this->once())->method('isStarted')->willReturn(true); |
||
90 | $session->expects($this->exactly(2))->method('has')->willReturn(false); |
||
91 | |||
92 | $listener = new SessionSecurityListener(true, true, $logger); |
||
93 | $listener->onKernelResponse($event); |
||
94 | } |
||
95 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.