Completed
Push — migrate-files-no-interaction ( 025687...608925 )
by
unknown
46:43 queued 18:48
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\API\Repository\Repository;
12
use eZ\Publish\API\Repository\UserService;
13
use eZ\Publish\API\Repository\Values\User\User;
14
use eZ\Publish\Core\REST\Server\Tests\BaseTest;
15
use eZ\Publish\Core\REST\Server\Authenticator\IntegrationTest;
16
use Qafoo\RMF;
17
18
/**
19
 * IntegrationTestTest.
20
 *
21
 * @todo Remove when the REST client is refactored
22
 */
23
class IntegrationTestTest extends BaseTest
24
{
25
    /**
26
     * @var \PHPUnit_Framework_MockObject_MockObject
27
     */
28
    protected $repositoryMock;
29
30
    /**
31
     * @var \PHPUnit_Framework_MockObject_MockObject
32
     */
33
    protected $userServiceMock;
34
35
    public function testAuthenticate()
36
    {
37
        $auth = new IntegrationTest($this->getRepositoryMock());
38
39
        $this->getUserServiceMock()
40
            ->expects($this->once())
41
            ->method('loadUser')
42
            ->with(23)
43
            ->will(
44
                $this->returnValue(
45
                    $user = $this->createMock(User::class)
46
                )
47
            );
48
49
        $this->getRepositoryMock()
50
            ->expects($this->once())
51
            ->method('setCurrentUser')
52
            ->with($user);
53
54
        $request = new RMF\Request();
55
        $request->testUser = 23;
56
57
        $auth->authenticate($request);
58
    }
59
60
    /**
61
     * @return \eZ\Publish\API\Repository\Repository
62
     */
63
    protected function getRepositoryMock()
64
    {
65
        if (!isset($this->repositoryMock)) {
66
            $this->repositoryMock = $this->createMock(Repository::class);
67
68
            $userServiceMock = $this->getUserServiceMock();
69
70
            $this->repositoryMock->expects($this->any())
71
                ->method('getUserService')
72
                ->will(
73
                    $this->returnCallback(
74
                        function () use ($userServiceMock) {
75
                            return $userServiceMock;
76
                        }
77
                    )
78
                );
79
        }
80
81
        return $this->repositoryMock;
82
    }
83
84
    /**
85
     * @return \eZ\Publish\API\Repository\UserService
86
     */
87
    protected function getUserServiceMock()
88
    {
89
        if (!isset($this->userServiceMock)) {
90
            $this->userServiceMock = $this->createMock(UserService::class);
91
        }
92
93
        return $this->userServiceMock;
94
    }
95
}
96