Completed
Push — 6.12 ( b5e32f...9aa285 )
by André
26:35 queued 11:42
created

testLogoutWithoutSiteaccessSessionSettings()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 25
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 28
rs 8.8571
1
<?php
2
3
/**
4
 * File containing the RestLogoutHandlerTest class.
5
 *
6
 * @copyright Copyright (C) 1999-2014 eZ Systems AS. All rights reserved.
7
 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
8
 */
9
namespace eZ\Publish\Core\REST\Server\Tests\Security;
10
11
use eZ\Publish\Core\Base\Tests\PHPUnit5CompatTrait;
12
use eZ\Publish\Core\MVC\ConfigResolverInterface;
13
use eZ\Publish\Core\REST\Server\Security\RestLogoutHandler;
14
use PHPUnit\Framework\TestCase;
15
use Symfony\Component\HttpFoundation\Request;
16
use Symfony\Component\HttpFoundation\Response;
17
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
18
use Symfony\Component\HttpFoundation\Session\SessionInterface;
19
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
20
21
class RestLogoutHandlerTest extends TestCase
22
{
23
    use PHPUnit5CompatTrait;
24
25
    /**
26
     * @var \PHPUnit_Framework_MockObject_MockObject
27
     */
28
    private $configResolver;
29
30
    /**
31
     * @var \PHPUnit_Framework_MockObject_MockObject
32
     */
33
    private $session;
34
35
    protected function setUp()
36
    {
37
        parent::setUp();
38
        $this->configResolver = $this->createMock(ConfigResolverInterface::class);
39
        $this->session = $this->createMock(SessionInterface::class);
40
    }
41
42
    public function testLogoutWithoutSiteaccessSessionSettings()
43
    {
44
        $sessionId = 'eZSESSID';
45
        $this->session
46
            ->expects($this->once())
47
            ->method('getName')
48
            ->will($this->returnValue($sessionId));
49
        $request = new Request();
50
        $request->setSession($this->session);
51
        $request->attributes->set('is_rest_request', true);
52
        $this->configResolver
53
            ->expects($this->once())
54
            ->method('getParameter')
55
            ->with('session')
56
            ->will($this->returnValue([]));
57
        $response = new Response();
58
        $response->headers = $this->createMock(ResponseHeaderBag::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Symfo...sponseHeaderBag::class) of type object<PHPUnit_Framework_MockObject_MockObject> is incompatible with the declared type object<Symfony\Component...tion\ResponseHeaderBag> of property $headers.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
59
        $response->headers
60
            ->expects($this->once())
61
            ->method('clearCookie')
62
            ->with($sessionId);
63
        $logoutHandler = new RestLogoutHandler($this->configResolver);
64
        $logoutHandler->logout(
65
            $request,
66
            $response,
67
            $this->createMock(TokenInterface::class)
68
        );
69
    }
70
71
    public function testLogoutWithSiteaccessSessionSettings()
72
    {
73
        $sessionId = 'eZSESSID';
74
        $this->session
75
            ->expects($this->once())
76
            ->method('getName')
77
            ->will($this->returnValue($sessionId));
78
        $request = new Request();
79
        $request->setSession($this->session);
80
        $request->attributes->set('is_rest_request', true);
81
        $sessionSettings = [
82
            'cookie_path' => '/',
83
            'cookie_domain' => 'ez.no',
84
        ];
85
        $this->configResolver
86
            ->expects($this->once())
87
            ->method('getParameter')
88
            ->with('session')
89
            ->will($this->returnValue($sessionSettings));
90
        $response = new Response();
91
        $response->headers = $this->createMock(ResponseHeaderBag::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Symfo...sponseHeaderBag::class) of type object<PHPUnit_Framework_MockObject_MockObject> is incompatible with the declared type object<Symfony\Component...tion\ResponseHeaderBag> of property $headers.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
92
        $response->headers
93
            ->expects($this->once())
94
            ->method('clearCookie')
95
            ->with($sessionId, $sessionSettings['cookie_path'], $sessionSettings['cookie_domain']);
96
        $logoutHandler = new RestLogoutHandler($this->configResolver);
97
        $logoutHandler->logout(
98
            $request,
99
            $response,
100
            $this->createMock(TokenInterface::class)
101
        );
102
    }
103
104
    public function testLogoutNotRest()
105
    {
106
        $session = $this->getMock('Symfony\Component\HttpFoundation\Session\SessionInterface');
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Base\Tes...5CompatTrait::getMock() has been deprecated with message: Since PHPUnit 5.4, marked as deprecated here to make it clear when working on 6.7/5.4 branches
{@inheritdoc}

This method has been deprecated. The supplier of the class has supplied an explanatory message.

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

Loading history...
107
        $session
108
            ->expects($this->never())
109
            ->method('getName');
110
111
        $request = new Request();
112
        $request->setSession($session);
113
114
        $response = new Response();
115
        $response->headers = $this->getMock('Symfony\Component\HttpFoundation\ResponseHeaderBag');
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Base\Tes...5CompatTrait::getMock() has been deprecated with message: Since PHPUnit 5.4, marked as deprecated here to make it clear when working on 6.7/5.4 branches
{@inheritdoc}

This method has been deprecated. The supplier of the class has supplied an explanatory message.

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

Loading history...
116
        $response->headers
117
            ->expects($this->never())
118
            ->method('clearCookie');
119
120
        $logoutHandler = new RestLogoutHandler($this->configResolver);
121
        $logoutHandler->logout(
122
            $request,
123
            $response,
124
            $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Base\Tes...5CompatTrait::getMock() has been deprecated with message: Since PHPUnit 5.4, marked as deprecated here to make it clear when working on 6.7/5.4 branches
{@inheritdoc}

This method has been deprecated. The supplier of the class has supplied an explanatory message.

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

Loading history...
125
        );
126
    }
127
}
128