Completed
Push — master ( 28c8cd...7e44c6 )
by André
18:53
created

BaseTest::getPermissionResolverMock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing the BaseTest 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\MVC\Symfony\Matcher\Tests\ContentBased;
10
11
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
12
use eZ\Publish\API\Repository\Values\Content\Location;
13
use eZ\Publish\Core\Repository\Permission\PermissionResolver;
14
use eZ\Publish\Core\Repository\Helper\RoleDomainMapper;
15
use eZ\Publish\API\Repository\Values\User\UserReference;
16
use eZ\Publish\SPI\Persistence\User\Handler as SPIUserHandler;
17
use eZ\Publish\Core\Repository\Helper\LimitationService;
18
use eZ\Publish\Core\MVC\Symfony\View\Provider\Location\Configured;
19
use eZ\Publish\Core\Repository\Repository;
20
use PHPUnit\Framework\TestCase;
21
22
abstract class BaseTest extends TestCase
23
{
24
    /**
25
     * @var \PHPUnit_Framework_MockObject_MockObject
26
     */
27
    protected $repositoryMock;
28
29
    protected function setUp()
30
    {
31
        parent::setUp();
32
        $this->repositoryMock = $this->getRepositoryMock();
33
    }
34
35
    /**
36
     * @param array $matchingConfig
37
     *
38
     * @return \PHPUnit_Framework_MockObject_MockObject
39
     */
40
    protected function getPartiallyMockedViewProvider(array $matchingConfig = array())
41
    {
42
        return $this
43
            ->getMockBuilder(Configured::class)
44
            ->setConstructorArgs(
45
                array(
46
                    $this->repositoryMock,
47
                    $matchingConfig,
48
                )
49
            )
50
            ->setMethods(array('getMatcher'))
51
            ->getMock();
52
    }
53
54
    /**
55
     * @return \PHPUnit_Framework_MockObject_MockObject
56
     */
57
    protected function getRepositoryMock()
58
    {
59
        $repositoryClass = Repository::class;
60
61
        return $this
62
            ->getMockBuilder($repositoryClass)
63
            ->disableOriginalConstructor()
64
            ->setMethods(
65
                array_diff(
66
                    get_class_methods($repositoryClass),
67
                    array('sudo')
68
                )
69
            )
70
            ->getMock();
71
    }
72
73
    /**
74
     * @param array $properties
75
     *
76
     * @return \PHPUnit_Framework_MockObject_MockObject
77
     */
78
    protected function getLocationMock(array $properties = array())
79
    {
80
        return $this
81
            ->getMockBuilder(Location::class)
82
            ->setConstructorArgs(array($properties))
83
            ->getMockForAbstractClass();
84
    }
85
86
    /**
87
     * @param array $properties
88
     *
89
     * @return \PHPUnit_Framework_MockObject_MockObject
90
     */
91
    protected function getContentInfoMock(array $properties = array())
92
    {
93
        return $this->
94
            getMockBuilder(ContentInfo::class)
95
            ->setConstructorArgs(array($properties))
96
            ->getMockForAbstractClass();
97
    }
98
99
    protected function getPermissionResolverMock()
100
    {
101
        return $this
102
            ->getMockBuilder(PermissionResolver::class)
103
            ->setMethods(null)
104
            ->setConstructorArgs(
105
                [
106
                    $this->createMock(RoleDomainMapper::class),
107
                    $this->createMock(LimitationService::class),
108
                    $this->createMock(SPIUserHandler::class),
109
                    $this->createMock(UserReference::class),
110
                ]
111
            )
112
            ->getMock();
113
    }
114
}
115