Completed
Push — fix_travis_behat ( 3c7f1b...b1b900 )
by
unknown
54:25 queued 34:54
created

IntegrationTestTest::testAuthenticate()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 16
nc 1
nop 0
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing a test class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\REST\Server\Tests\Authenticator;
10
11
use eZ\Publish\Core\REST\Server\Tests\BaseTest;
12
use eZ\Publish\Core\REST\Server\Authenticator\IntegrationTest;
13
use Qafoo\RMF;
14
15
/**
16
 * IntegrationTestTest.
17
 *
18
 * @todo Remove when the REST client is refactored
19
 */
20
class IntegrationTestTest extends BaseTest
21
{
22
    /**
23
     * @var \PHPUnit_Framework_MockObject_MockObject
24
     */
25
    protected $repositoryMock;
26
27
    /**
28
     * @var \PHPUnit_Framework_MockObject_MockObject
29
     */
30
    protected $userServiceMock;
31
32
    public function testAuthenticate()
33
    {
34
        $auth = new IntegrationTest($this->getRepositoryMock());
35
36
        $this->getUserServiceMock()
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\API\Repository\UserService>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
37
            ->expects($this->once())
38
            ->method('loadUser')
39
            ->with(23)
40
            ->will(
41
                $this->returnValue(
42
                    $user = $this->getMock('eZ\\Publish\\API\\Repository\\Values\\User\\User')
43
                )
44
            );
45
46
        $this->getRepositoryMock()
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\API\Repository\Repository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
47
            ->expects($this->once())
48
            ->method('setCurrentUser')
49
            ->with($user);
50
51
        $request = new RMF\Request();
52
        $request->testUser = 23;
53
54
        $auth->authenticate($request);
55
    }
56
57
    /**
58
     * @return \eZ\Publish\API\Repository\Repository
59
     */
60
    protected function getRepositoryMock()
61
    {
62
        if (!isset($this->repositoryMock)) {
63
            $this->repositoryMock = $this->getMock(
64
                '\\eZ\\Publish\\API\\Repository\\Repository',
65
                array(),
66
                array(),
67
                '',
68
                false
69
            );
70
71
            $userServiceMock = $this->getUserServiceMock();
72
73
            $this->repositoryMock->expects($this->any())
74
                ->method('getUserService')
75
                ->will(
76
                    $this->returnCallback(
77
                        function () use ($userServiceMock) {
78
                            return $userServiceMock;
79
                        }
80
                    )
81
                );
82
        }
83
84
        return $this->repositoryMock;
85
    }
86
87
    /**
88
     * @return \eZ\Publish\API\Repository\UserService
89
     */
90
    protected function getUserServiceMock()
91
    {
92
        if (!isset($this->userServiceMock)) {
93
            $this->userServiceMock = $this->getMock(
94
                '\\eZ\\Publish\\API\\Repository\\UserService',
95
                array(),
96
                array(),
97
                '',
98
                false
99
            );
100
        }
101
102
        return $this->userServiceMock;
103
    }
104
}
105