Completed
Push — master ( e2d26f...9ff6cb )
by André
24:47
created

testFindSingleValidatesLocationCriteria()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 17

Duplication

Lines 24
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 17
nc 2
nop 2
dl 24
loc 24
rs 8.9713
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File contains: eZ\Publish\Core\Repository\Tests\Service\Mock\SearchTest 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\Repository\Tests\Service\Mock;
10
11
use eZ\Publish\Core\Repository\Tests\Service\Mock\Base as BaseServiceMockTest;
12
use eZ\Publish\Core\Repository\SearchService;
13
use eZ\Publish\API\Repository\Values\Content\Query;
14
use eZ\Publish\API\Repository\Values\Content\LocationQuery;
15
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
16
use eZ\Publish\API\Repository\Values\Content\Query\SortClause;
17
use eZ\Publish\API\Repository\Values\Content\Search\SearchResult;
18
use eZ\Publish\API\Repository\Values\Content\Search\SearchHit;
19
use eZ\Publish\SPI\Persistence\Content\ContentInfo as SPIContentInfo;
20
use eZ\Publish\SPI\Persistence\Content\Location as SPILocation;
21
use eZ\Publish\API\Repository\Exceptions\InvalidArgumentException;
22
use Exception;
23
24
/**
25
 * Mock test case for Search service.
26
 */
27
class SearchTest extends BaseServiceMockTest
28
{
29
    protected $repositoryMock;
30
31
    protected $domainMapperMock;
32
33
    protected $permissionsCriterionHandlerMock;
34
35
    /**
36
     * Test for the __construct() method.
37
     *
38
     * @covers \eZ\Publish\Core\Repository\SearchService::__construct
39
     */
40
    public function testConstructor()
41
    {
42
        $repositoryMock = $this->getRepositoryMock();
43
        /** @var \eZ\Publish\SPI\Search\Handler $searchHandlerMock */
44
        $searchHandlerMock = $this->getSPIMockHandler('Search\\Handler');
45
        $domainMapperMock = $this->getDomainMapperMock();
46
        $permissionsCriterionHandlerMock = $this->getPermissionsCriterionHandlerMock();
47
        $sortClauseMapperMock = $this->getSortClauseMapperMock();
48
        $settings = array('teh setting');
49
50
        $service = new SearchService(
51
            $repositoryMock,
0 ignored issues
show
Bug introduced by
It seems like $repositoryMock defined by $this->getRepositoryMock() on line 42 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\API\Repository\Repository>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
52
            $searchHandlerMock,
53
            $domainMapperMock,
0 ignored issues
show
Bug introduced by
It seems like $domainMapperMock defined by $this->getDomainMapperMock() on line 45 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...ry\Helper\DomainMapper>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
54
            $permissionsCriterionHandlerMock,
0 ignored issues
show
Bug introduced by
It seems like $permissionsCriterionHandlerMock defined by $this->getPermissionsCriterionHandlerMock() on line 46 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...ssionsCriterionHandler>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
55
            $sortClauseMapperMock,
0 ignored issues
show
Bug introduced by
It seems like $sortClauseMapperMock defined by $this->getSortClauseMapperMock() on line 47 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...apper\SortClauseMapper>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
56
            $settings
57
        );
58
59
        $this->assertAttributeSame(
60
            $repositoryMock,
61
            'repository',
62
            $service
63
        );
64
65
        $this->assertAttributeSame(
66
            $searchHandlerMock,
67
            'searchHandler',
68
            $service
69
        );
70
71
        $this->assertAttributeSame(
72
            $domainMapperMock,
73
            'domainMapper',
74
            $service
75
        );
76
77
        $this->assertAttributeSame(
78
            $permissionsCriterionHandlerMock,
79
            'permissionsCriterionHandler',
80
            $service
81
        );
82
83
        $this->assertAttributeSame(
84
            $sortClauseMapperMock,
85
            'sortClauseMapper',
86
            $service
87
        );
88
89
        $this->assertAttributeSame(
90
            $settings,
91
            'settings',
92
            $service
93
        );
94
    }
95
96
    public function providerForFindContentValidatesLocationCriteriaAndSortClauses()
97
    {
98
        return array(
99
            array(
100
                new Query(array('filter' => new Criterion\Location\Depth(Criterion\Operator::LT, 2))),
101
                "Argument '\$query' is invalid: Location criterions cannot be used in Content search",
102
            ),
103
            array(
104
                new Query(array('query' => new Criterion\Location\Depth(Criterion\Operator::LT, 2))),
105
                "Argument '\$query' is invalid: Location criterions cannot be used in Content search",
106
            ),
107
            array(
108
                new Query(
109
                    array(
110
                        'query' => new Criterion\LogicalAnd(
111
                            array(
112
                                new Criterion\Location\Depth(Criterion\Operator::LT, 2),
113
                            )
114
                        ),
115
                    )
116
                ),
117
                "Argument '\$query' is invalid: Location criterions cannot be used in Content search",
118
            ),
119
            array(
120
                new Query(array('sortClauses' => array(new SortClause\Location\Id()))),
121
                "Argument '\$query' is invalid: Location sort clauses cannot be used in Content search",
122
            ),
123
        );
124
    }
125
126
    /**
127
     * @dataProvider providerForFindContentValidatesLocationCriteriaAndSortClauses
128
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
129
     */
130 View Code Duplication
    public function testFindContentValidatesLocationCriteriaAndSortClauses($query, $exceptionMessage)
131
    {
132
        $repositoryMock = $this->getRepositoryMock();
133
        /** @var \eZ\Publish\SPI\Search\Handler $searchHandlerMock */
134
        $searchHandlerMock = $this->getSPIMockHandler('Search\\Handler');
135
        $permissionsCriterionHandlerMock = $this->getPermissionsCriterionHandlerMock();
136
137
        $service = new SearchService(
138
            $repositoryMock,
0 ignored issues
show
Bug introduced by
It seems like $repositoryMock defined by $this->getRepositoryMock() on line 132 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\API\Repository\Repository>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
139
            $searchHandlerMock,
140
            $this->getDomainMapperMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getDomainMapperMock() targeting eZ\Publish\Core\Reposito...::getDomainMapperMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...ry\Helper\DomainMapper>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
141
            $permissionsCriterionHandlerMock,
0 ignored issues
show
Bug introduced by
It seems like $permissionsCriterionHandlerMock defined by $this->getPermissionsCriterionHandlerMock() on line 135 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...ssionsCriterionHandler>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
142
            $this->getSortClauseMapperMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getSortClauseMapperMock() targeting eZ\Publish\Core\Reposito...tSortClauseMapperMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...apper\SortClauseMapper>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
143
            array()
144
        );
145
146
        try {
147
            $service->findContent($query);
148
        } catch (InvalidArgumentException $e) {
149
            $this->assertEquals($exceptionMessage, $e->getMessage());
150
            throw $e;
151
        }
152
153
        $this->fail('Expected exception was not thrown');
154
    }
155
156
    public function providerForFindSingleValidatesLocationCriteria()
157
    {
158
        return array(
159
            array(
160
                new Criterion\Location\Depth(Criterion\Operator::LT, 2),
161
                "Argument '\$filter' is invalid: Location criterions cannot be used in Content search",
162
            ),
163
            array(
164
                new Criterion\LogicalAnd(
165
                    array(
166
                        new Criterion\Location\Depth(Criterion\Operator::LT, 2),
167
                    )
168
                ),
169
                "Argument '\$filter' is invalid: Location criterions cannot be used in Content search",
170
            ),
171
        );
172
    }
173
174
    /**
175
     * @dataProvider providerForFindSingleValidatesLocationCriteria
176
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
177
     */
178 View Code Duplication
    public function testFindSingleValidatesLocationCriteria($criterion, $exceptionMessage)
179
    {
180
        $repositoryMock = $this->getRepositoryMock();
181
        /** @var \eZ\Publish\SPI\Search\Handler $searchHandlerMock */
182
        $searchHandlerMock = $this->getSPIMockHandler('Search\\Handler');
183
        $permissionsCriterionHandlerMock = $this->getPermissionsCriterionHandlerMock();
184
        $service = new SearchService(
185
            $repositoryMock,
0 ignored issues
show
Bug introduced by
It seems like $repositoryMock defined by $this->getRepositoryMock() on line 180 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\API\Repository\Repository>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
186
            $searchHandlerMock,
187
            $this->getDomainMapperMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getDomainMapperMock() targeting eZ\Publish\Core\Reposito...::getDomainMapperMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...ry\Helper\DomainMapper>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
188
            $permissionsCriterionHandlerMock,
0 ignored issues
show
Bug introduced by
It seems like $permissionsCriterionHandlerMock defined by $this->getPermissionsCriterionHandlerMock() on line 183 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...ssionsCriterionHandler>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
189
            $this->getSortClauseMapperMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getSortClauseMapperMock() targeting eZ\Publish\Core\Reposito...tSortClauseMapperMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...apper\SortClauseMapper>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
190
            array()
191
        );
192
193
        try {
194
            $service->findSingle($criterion);
195
        } catch (InvalidArgumentException $e) {
196
            $this->assertEquals($exceptionMessage, $e->getMessage());
197
            throw $e;
198
        }
199
200
        $this->fail('Expected exception was not thrown');
201
    }
202
203
    /**
204
     * Test for the findContent() method.
205
     *
206
     * @covers \eZ\Publish\Core\Repository\PermissionsCriterionHandler::addPermissionsCriterion
207
     * @covers \eZ\Publish\Core\Repository\PermissionsCriterionHandler::getPermissionsCriterion
208
     * @covers \eZ\Publish\Core\Repository\SearchService::findContent
209
     * @expectedException \Exception
210
     * @expectedExceptionMessage Handler threw an exception
211
     */
212 View Code Duplication
    public function testFindContentThrowsHandlerException()
213
    {
214
        $repositoryMock = $this->getRepositoryMock();
215
        /** @var \eZ\Publish\SPI\Search\Handler $searchHandlerMock */
216
        $searchHandlerMock = $this->getSPIMockHandler('Search\\Handler');
217
        $permissionsCriterionHandlerMock = $this->getPermissionsCriterionHandlerMock();
218
219
        $service = new SearchService(
220
            $repositoryMock,
0 ignored issues
show
Bug introduced by
It seems like $repositoryMock defined by $this->getRepositoryMock() on line 214 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\API\Repository\Repository>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
221
            $searchHandlerMock,
222
            $this->getDomainMapperMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getDomainMapperMock() targeting eZ\Publish\Core\Reposito...::getDomainMapperMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...ry\Helper\DomainMapper>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
223
            $permissionsCriterionHandlerMock,
0 ignored issues
show
Bug introduced by
It seems like $permissionsCriterionHandlerMock defined by $this->getPermissionsCriterionHandlerMock() on line 217 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...ssionsCriterionHandler>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
224
            $this->getSortClauseMapperMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getSortClauseMapperMock() targeting eZ\Publish\Core\Reposito...tSortClauseMapperMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...apper\SortClauseMapper>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
225
            array()
226
        );
227
228
        /** @var \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterionMock */
229
        $criterionMock = $this
230
            ->getMockBuilder('eZ\\Publish\\API\\Repository\\Values\\Content\\Query\\Criterion')
231
            ->disableOriginalConstructor()
232
            ->getMock();
233
        $query = new Query(array('filter' => $criterionMock));
234
235
        $permissionsCriterionHandlerMock->expects($this->once())
236
            ->method('addPermissionsCriterion')
237
            ->with($criterionMock)
238
            ->will($this->throwException(new Exception('Handler threw an exception')));
239
240
        $service->findContent($query, array(), true);
241
    }
242
243
    /**
244
     * Test for the findContent() method.
245
     *
246
     * @covers \eZ\Publish\Core\Repository\PermissionsCriterionHandler::addPermissionsCriterion
247
     * @covers \eZ\Publish\Core\Repository\PermissionsCriterionHandler::getPermissionsCriterion
248
     * @covers \eZ\Publish\Core\Repository\SearchService::findContent
249
     */
250
    public function testFindContentNoPermissionsFilter()
251
    {
252
        $repositoryMock = $this->getRepositoryMock();
253
        /** @var \eZ\Publish\SPI\Search\Handler $searchHandlerMock */
254
        $searchHandlerMock = $this->getSPIMockHandler('Search\\Handler');
255
        $domainMapperMock = $this->getDomainMapperMock();
256
        $permissionsCriterionHandlerMock = $this->getPermissionsCriterionHandlerMock();
257
        $service = new SearchService(
258
            $repositoryMock,
0 ignored issues
show
Bug introduced by
It seems like $repositoryMock defined by $this->getRepositoryMock() on line 252 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\API\Repository\Repository>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
259
            $searchHandlerMock,
260
            $domainMapperMock,
0 ignored issues
show
Bug introduced by
It seems like $domainMapperMock defined by $this->getDomainMapperMock() on line 255 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...ry\Helper\DomainMapper>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
261
            $permissionsCriterionHandlerMock,
0 ignored issues
show
Bug introduced by
It seems like $permissionsCriterionHandlerMock defined by $this->getPermissionsCriterionHandlerMock() on line 256 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...ssionsCriterionHandler>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
262
            $this->getSortClauseMapperMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getSortClauseMapperMock() targeting eZ\Publish\Core\Reposito...tSortClauseMapperMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...apper\SortClauseMapper>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
263
            array()
264
        );
265
266
        $repositoryMock->expects($this->never())->method('hasAccess');
267
268
        $repositoryMock
269
            ->expects($this->once())
270
            ->method('getContentService')
271
            ->will(
272
                $this->returnValue(
273
                    $contentServiceMock = $this
274
                        ->getMockBuilder('eZ\\Publish\\Core\\Repository\\ContentService')
275
                        ->disableOriginalConstructor()
276
                        ->getMock()
277
                )
278
            );
279
280
        $serviceQuery = new Query();
281
        $handlerQuery = new Query(array('filter' => new Criterion\MatchAll(), 'limit' => 25));
282
        $languageFilter = array();
283
        $spiContentInfo = new SPIContentInfo();
284
        $contentMock = $this->getMockForAbstractClass('eZ\\Publish\\API\\Repository\\Values\\Content\\Content');
285
286
        /* @var \PHPUnit_Framework_MockObject_MockObject $searchHandlerMock */
287
        $searchHandlerMock->expects($this->once())
288
            ->method('findContent')
289
            ->with($this->equalTo($handlerQuery), $this->equalTo($languageFilter))
290
            ->will(
291
                $this->returnValue(
292
                    new SearchResult(
293
                        array(
294
                            'searchHits' => array(new SearchHit(array('valueObject' => $spiContentInfo))),
295
                            'totalCount' => 1,
296
                        )
297
                    )
298
                )
299
            );
300
301
        $contentServiceMock
302
            ->expects($this->once())
303
            ->method('internalLoadContent')
304
            ->will($this->returnValue($contentMock));
305
306
        $result = $service->findContent($serviceQuery, $languageFilter, false);
307
308
        $this->assertEquals(
309
            new SearchResult(
310
                array(
311
                    'searchHits' => array(new SearchHit(array('valueObject' => $contentMock))),
312
                    'totalCount' => 1,
313
                )
314
            ),
315
            $result
316
        );
317
    }
318
319
    /**
320
     * Test for the findContent() method.
321
     *
322
     * @covers \eZ\Publish\Core\Repository\PermissionsCriterionHandler::addPermissionsCriterion
323
     * @covers \eZ\Publish\Core\Repository\PermissionsCriterionHandler::getPermissionsCriterion
324
     * @covers \eZ\Publish\Core\Repository\SearchService::findContent
325
     */
326
    public function testFindContentWithPermission()
327
    {
328
        $repositoryMock = $this->getRepositoryMock();
329
        /** @var \eZ\Publish\SPI\Search\Handler $searchHandlerMock */
330
        $searchHandlerMock = $this->getSPIMockHandler('Search\\Handler');
331
        $domainMapperMock = $this->getDomainMapperMock();
332
        $permissionsCriterionHandlerMock = $this->getPermissionsCriterionHandlerMock();
333
        $service = new SearchService(
334
            $repositoryMock,
0 ignored issues
show
Bug introduced by
It seems like $repositoryMock defined by $this->getRepositoryMock() on line 328 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\API\Repository\Repository>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
335
            $searchHandlerMock,
336
            $domainMapperMock,
0 ignored issues
show
Bug introduced by
It seems like $domainMapperMock defined by $this->getDomainMapperMock() on line 331 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...ry\Helper\DomainMapper>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
337
            $permissionsCriterionHandlerMock,
0 ignored issues
show
Bug introduced by
It seems like $permissionsCriterionHandlerMock defined by $this->getPermissionsCriterionHandlerMock() on line 332 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...ssionsCriterionHandler>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
338
            $this->getSortClauseMapperMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getSortClauseMapperMock() targeting eZ\Publish\Core\Reposito...tSortClauseMapperMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...apper\SortClauseMapper>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
339
            array()
340
        );
341
342
        $repositoryMock
343
            ->expects($this->once())
344
            ->method('getContentService')
345
            ->will(
346
                $this->returnValue(
347
                    $contentServiceMock = $this
348
                        ->getMockBuilder('eZ\\Publish\\Core\\Repository\\ContentService')
349
                        ->disableOriginalConstructor()
350
                        ->getMock()
351
                )
352
            );
353
354
        $criterionMock = $this
355
            ->getMockBuilder('eZ\\Publish\\API\\Repository\\Values\\Content\\Query\\Criterion')
356
            ->disableOriginalConstructor()
357
            ->getMock();
358
        $query = new Query(array('filter' => $criterionMock, 'limit' => 10));
359
        $languageFilter = array();
360
        $spiContentInfo = new SPIContentInfo();
361
        $contentMock = $this->getMockForAbstractClass('eZ\\Publish\\API\\Repository\\Values\\Content\\Content');
362
363
        /* @var \PHPUnit_Framework_MockObject_MockObject $searchHandlerMock */
364
        $searchHandlerMock->expects($this->once())
365
            ->method('findContent')
366
            ->with($this->equalTo($query), $this->equalTo($languageFilter))
367
            ->will(
368
                $this->returnValue(
369
                    new SearchResult(
370
                        array(
371
                            'searchHits' => array(new SearchHit(array('valueObject' => $spiContentInfo))),
372
                            'totalCount' => 1,
373
                        )
374
                    )
375
                )
376
            );
377
378
        $domainMapperMock->expects($this->never())
379
            ->method($this->anything());
380
381
        $contentServiceMock
382
            ->expects($this->once())
383
            ->method('internalLoadContent')
384
            ->will($this->returnValue($contentMock));
385
386
        $permissionsCriterionHandlerMock->expects($this->once())
387
            ->method('addPermissionsCriterion')
388
            ->with($criterionMock)
389
            ->will($this->returnValue(true));
390
391
        $result = $service->findContent($query, $languageFilter, true);
392
393
        $this->assertEquals(
394
            new SearchResult(
395
                array(
396
                    'searchHits' => array(new SearchHit(array('valueObject' => $contentMock))),
397
                    'totalCount' => 1,
398
                )
399
            ),
400
            $result
401
        );
402
    }
403
404
    /**
405
     * Test for the findContent() method.
406
     *
407
     * @covers \eZ\Publish\Core\Repository\PermissionsCriterionHandler::addPermissionsCriterion
408
     * @covers \eZ\Publish\Core\Repository\PermissionsCriterionHandler::getPermissionsCriterion
409
     * @covers \eZ\Publish\Core\Repository\SearchService::findContent
410
     */
411
    public function testFindContentWithNoPermission()
412
    {
413
        $repositoryMock = $this->getRepositoryMock();
414
        /** @var \eZ\Publish\SPI\Search\Handler $searchHandlerMock */
415
        $searchHandlerMock = $this->getSPIMockHandler('Search\\Handler');
416
        $permissionsCriterionHandlerMock = $this->getPermissionsCriterionHandlerMock();
417
        $service = new SearchService(
418
            $repositoryMock,
0 ignored issues
show
Bug introduced by
It seems like $repositoryMock defined by $this->getRepositoryMock() on line 413 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\API\Repository\Repository>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
419
            $searchHandlerMock,
420
            $this->getDomainMapperMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getDomainMapperMock() targeting eZ\Publish\Core\Reposito...::getDomainMapperMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...ry\Helper\DomainMapper>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
421
            $permissionsCriterionHandlerMock,
0 ignored issues
show
Bug introduced by
It seems like $permissionsCriterionHandlerMock defined by $this->getPermissionsCriterionHandlerMock() on line 416 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...ssionsCriterionHandler>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
422
            $this->getSortClauseMapperMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getSortClauseMapperMock() targeting eZ\Publish\Core\Reposito...tSortClauseMapperMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...apper\SortClauseMapper>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
423
            array()
424
        );
425
426
        /* @var \PHPUnit_Framework_MockObject_MockObject $searchHandlerMock */
427
        $searchHandlerMock->expects($this->never())->method('findContent');
428
429
        $criterionMock = $this
430
            ->getMockBuilder('eZ\\Publish\\API\\Repository\\Values\\Content\\Query\\Criterion')
431
            ->disableOriginalConstructor()
432
            ->getMock();
433
        $query = new Query(array('filter' => $criterionMock));
434
435
        $permissionsCriterionHandlerMock->expects($this->once())
436
            ->method('addPermissionsCriterion')
437
            ->with($criterionMock)
438
            ->will($this->returnValue(false));
439
440
        $result = $service->findContent($query, array(), true);
441
442
        $this->assertEquals(
443
            new SearchResult(array('time' => 0, 'totalCount' => 0)),
444
            $result
445
        );
446
    }
447
448
    /**
449
     * Test for the findContent() method.
450
     */
451
    public function testFindContentWithDefaultQueryValues()
452
    {
453
        $repositoryMock = $this->getRepositoryMock();
454
        /** @var \eZ\Publish\SPI\Search\Handler $searchHandlerMock */
455
        $searchHandlerMock = $this->getSPIMockHandler('Search\\Handler');
456
        $domainMapperMock = $this->getDomainMapperMock();
457
        $service = new SearchService(
458
            $repositoryMock,
0 ignored issues
show
Bug introduced by
It seems like $repositoryMock defined by $this->getRepositoryMock() on line 453 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\API\Repository\Repository>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
459
            $searchHandlerMock,
460
            $domainMapperMock,
0 ignored issues
show
Bug introduced by
It seems like $domainMapperMock defined by $this->getDomainMapperMock() on line 456 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...ry\Helper\DomainMapper>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
461
            $this->getPermissionsCriterionHandlerMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getPermissionsCriterionHandlerMock() targeting eZ\Publish\Core\Reposito...sCriterionHandlerMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...ssionsCriterionHandler>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
462
            $this->getSortClauseMapperMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getSortClauseMapperMock() targeting eZ\Publish\Core\Reposito...tSortClauseMapperMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...apper\SortClauseMapper>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
463
            array()
464
        );
465
466
        $repositoryMock
467
            ->expects($this->once())
468
            ->method('getContentService')
469
            ->will(
470
                $this->returnValue(
471
                    $contentServiceMock = $this
472
                        ->getMockBuilder('eZ\\Publish\\Core\\Repository\\ContentService')
473
                        ->disableOriginalConstructor()
474
                        ->getMock()
475
                )
476
            );
477
478
        $languageFilter = array();
479
        $spiContentInfo = new SPIContentInfo();
480
        $contentMock = $this->getMockForAbstractClass('eZ\\Publish\\API\\Repository\\Values\\Content\\Content');
481
        $domainMapperMock->expects($this->never())
482
            ->method($this->anything());
483
484
        $contentServiceMock
485
            ->expects($this->once())
486
            ->method('internalLoadContent')
487
            ->will($this->returnValue($contentMock));
488
489
        /* @var \PHPUnit_Framework_MockObject_MockObject $searchHandlerMock */
490
        $searchHandlerMock
491
            ->expects($this->once())
492
            ->method('findContent')
493
            ->with(
494
                new Query(
495
                    array(
496
                        'filter' => new Criterion\MatchAll(),
497
                        'limit' => 25,
498
                    )
499
                ),
500
                array()
501
            )
502
            ->will(
503
                $this->returnValue(
504
                    new SearchResult(
505
                        array(
506
                            'searchHits' => array(new SearchHit(array('valueObject' => $spiContentInfo))),
507
                            'totalCount' => 1,
508
                        )
509
                    )
510
                )
511
            );
512
513
        $result = $service->findContent(new Query(), $languageFilter, false);
514
515
        $this->assertEquals(
516
            new SearchResult(
517
                array(
518
                    'searchHits' => array(new SearchHit(array('valueObject' => $contentMock))),
519
                    'totalCount' => 1,
520
                )
521
            ),
522
            $result
523
        );
524
    }
525
526
    /**
527
     * Test for the findSingle() method.
528
     *
529
     * @covers \eZ\Publish\Core\Repository\PermissionsCriterionHandler::addPermissionsCriterion
530
     * @covers \eZ\Publish\Core\Repository\PermissionsCriterionHandler::getPermissionsCriterion
531
     * @covers \eZ\Publish\Core\Repository\SearchService::findSingle
532
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
533
     */
534
    public function testFindSingleThrowsNotFoundException()
535
    {
536
        $repositoryMock = $this->getRepositoryMock();
537
        /** @var \eZ\Publish\SPI\Search\Handler $searchHandlerMock */
538
        $searchHandlerMock = $this->getSPIMockHandler('Search\\Handler');
539
        $service = new SearchService(
540
            $repositoryMock,
0 ignored issues
show
Bug introduced by
It seems like $repositoryMock defined by $this->getRepositoryMock() on line 536 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\API\Repository\Repository>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
541
            $searchHandlerMock,
542
            $this->getDomainMapperMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getDomainMapperMock() targeting eZ\Publish\Core\Reposito...::getDomainMapperMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...ry\Helper\DomainMapper>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
543
            $this->getPermissionsCriterionHandlerMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getPermissionsCriterionHandlerMock() targeting eZ\Publish\Core\Reposito...sCriterionHandlerMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...ssionsCriterionHandler>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
544
            $this->getSortClauseMapperMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getSortClauseMapperMock() targeting eZ\Publish\Core\Reposito...tSortClauseMapperMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...apper\SortClauseMapper>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
545
            array()
546
        );
547
548
        /** @var \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterionMock */
549
        $criterionMock = $this
550
            ->getMockBuilder('eZ\\Publish\\API\\Repository\\Values\\Content\\Query\\Criterion')
551
            ->disableOriginalConstructor()
552
            ->getMock();
553
554
        $service->findSingle($criterionMock, array(), true);
555
    }
556
557
    /**
558
     * Test for the findSingle() method.
559
     *
560
     * @covers \eZ\Publish\Core\Repository\PermissionsCriterionHandler::addPermissionsCriterion
561
     * @covers \eZ\Publish\Core\Repository\PermissionsCriterionHandler::getPermissionsCriterion
562
     * @covers \eZ\Publish\Core\Repository\SearchService::findSingle
563
     * @expectedException \Exception
564
     * @expectedExceptionMessage Handler threw an exception
565
     */
566
    public function testFindSingleThrowsHandlerException()
567
    {
568
        $repositoryMock = $this->getRepositoryMock();
569
        /** @var \eZ\Publish\SPI\Search\Handler $searchHandlerMock */
570
        $searchHandlerMock = $this->getSPIMockHandler('Search\\Handler');
571
        $permissionsCriterionHandlerMock = $this->getPermissionsCriterionHandlerMock();
572
        $service = new SearchService(
573
            $repositoryMock,
0 ignored issues
show
Bug introduced by
It seems like $repositoryMock defined by $this->getRepositoryMock() on line 568 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\API\Repository\Repository>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
574
            $searchHandlerMock,
575
            $this->getDomainMapperMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getDomainMapperMock() targeting eZ\Publish\Core\Reposito...::getDomainMapperMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...ry\Helper\DomainMapper>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
576
            $permissionsCriterionHandlerMock,
0 ignored issues
show
Bug introduced by
It seems like $permissionsCriterionHandlerMock defined by $this->getPermissionsCriterionHandlerMock() on line 571 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...ssionsCriterionHandler>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
577
            $this->getSortClauseMapperMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getSortClauseMapperMock() targeting eZ\Publish\Core\Reposito...tSortClauseMapperMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...apper\SortClauseMapper>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
578
            array()
579
        );
580
581
        /** @var \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterionMock */
582
        $criterionMock = $this
583
            ->getMockBuilder('eZ\\Publish\\API\\Repository\\Values\\Content\\Query\\Criterion')
584
            ->disableOriginalConstructor()
585
            ->getMock();
586
587
        $permissionsCriterionHandlerMock->expects($this->once())
588
            ->method('addPermissionsCriterion')
589
            ->with($criterionMock)
590
            ->will($this->throwException(new Exception('Handler threw an exception')));
591
592
        $service->findSingle($criterionMock, array(), true);
593
    }
594
595
    /**
596
     * Test for the findSingle() method.
597
     *
598
     * @covers \eZ\Publish\Core\Repository\PermissionsCriterionHandler::addPermissionsCriterion
599
     * @covers \eZ\Publish\Core\Repository\PermissionsCriterionHandler::getPermissionsCriterion
600
     * @covers \eZ\Publish\Core\Repository\SearchService::findSingle
601
     */
602
    public function testFindSingle()
603
    {
604
        $repositoryMock = $this->getRepositoryMock();
605
        /** @var \eZ\Publish\SPI\Search\Handler $searchHandlerMock */
606
        $searchHandlerMock = $this->getSPIMockHandler('Search\\Handler');
607
        $domainMapperMock = $this->getDomainMapperMock();
608
        $permissionsCriterionHandlerMock = $this->getPermissionsCriterionHandlerMock();
609
        $service = new SearchService(
610
            $repositoryMock,
0 ignored issues
show
Bug introduced by
It seems like $repositoryMock defined by $this->getRepositoryMock() on line 604 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\API\Repository\Repository>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
611
            $searchHandlerMock,
612
            $domainMapperMock,
0 ignored issues
show
Bug introduced by
It seems like $domainMapperMock defined by $this->getDomainMapperMock() on line 607 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...ry\Helper\DomainMapper>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
613
            $permissionsCriterionHandlerMock,
0 ignored issues
show
Bug introduced by
It seems like $permissionsCriterionHandlerMock defined by $this->getPermissionsCriterionHandlerMock() on line 608 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...ssionsCriterionHandler>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
614
            $this->getSortClauseMapperMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getSortClauseMapperMock() targeting eZ\Publish\Core\Reposito...tSortClauseMapperMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...apper\SortClauseMapper>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
615
            array()
616
        );
617
618
        $repositoryMock
619
            ->expects($this->once())
620
            ->method('getContentService')
621
            ->will(
622
                $this->returnValue(
623
                    $contentServiceMock = $this
624
                        ->getMockBuilder('eZ\\Publish\\Core\\Repository\\ContentService')
625
                        ->disableOriginalConstructor()
626
                        ->getMock()
627
                )
628
            );
629
630
        /** @var \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterionMock */
631
        $criterionMock = $this
632
            ->getMockBuilder('eZ\\Publish\\API\\Repository\\Values\\Content\\Query\\Criterion')
633
            ->disableOriginalConstructor()
634
            ->getMock();
635
636
        $permissionsCriterionHandlerMock->expects($this->once())
637
            ->method('addPermissionsCriterion')
638
            ->with($criterionMock)
639
            ->will($this->returnValue(true));
640
641
        $languageFilter = array();
642
        $spiContentInfo = new SPIContentInfo();
643
        $contentMock = $this->getMockForAbstractClass('eZ\\Publish\\API\\Repository\\Values\\Content\\Content');
644
645
        /* @var \PHPUnit_Framework_MockObject_MockObject $searchHandlerMock */
646
        $searchHandlerMock->expects($this->once())
647
            ->method('findSingle')
648
            ->with($this->equalTo($criterionMock), $this->equalTo($languageFilter))
649
            ->will($this->returnValue($spiContentInfo));
650
651
        $domainMapperMock->expects($this->never())
652
            ->method($this->anything());
653
654
        $contentServiceMock
655
            ->expects($this->once())
656
            ->method('internalLoadContent')
657
            ->will($this->returnValue($contentMock));
658
659
        $result = $service->findSingle($criterionMock, $languageFilter, true);
660
661
        $this->assertEquals($contentMock, $result);
662
    }
663
664
    /**
665
     * Test for the findLocations() method.
666
     */
667
    public function testFindLocationsWithPermission()
668
    {
669
        $repositoryMock = $this->getRepositoryMock();
670
        /** @var \eZ\Publish\SPI\Search\Handler $searchHandlerMock */
671
        $searchHandlerMock = $this->getSPIMockHandler('Search\\Handler');
672
        $domainMapperMock = $this->getDomainMapperMock();
673
        $permissionsCriterionHandlerMock = $this->getPermissionsCriterionHandlerMock();
674
        $service = new SearchService(
675
            $repositoryMock,
0 ignored issues
show
Bug introduced by
It seems like $repositoryMock defined by $this->getRepositoryMock() on line 669 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\API\Repository\Repository>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
676
            $searchHandlerMock,
677
            $domainMapperMock,
0 ignored issues
show
Bug introduced by
It seems like $domainMapperMock defined by $this->getDomainMapperMock() on line 672 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...ry\Helper\DomainMapper>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
678
            $permissionsCriterionHandlerMock,
0 ignored issues
show
Bug introduced by
It seems like $permissionsCriterionHandlerMock defined by $this->getPermissionsCriterionHandlerMock() on line 673 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...ssionsCriterionHandler>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
679
            $this->getSortClauseMapperMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getSortClauseMapperMock() targeting eZ\Publish\Core\Reposito...tSortClauseMapperMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...apper\SortClauseMapper>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
680
            array()
681
        );
682
683
        $criterionMock = $this
684
            ->getMockBuilder('eZ\\Publish\\API\\Repository\\Values\\Content\\Query\\Criterion')
685
            ->disableOriginalConstructor()
686
            ->getMock();
687
        $query = new LocationQuery(array('filter' => $criterionMock, 'limit' => 10));
688
        $spiLocation = new SPILocation();
689
        $locationMock = $this->getMockForAbstractClass('eZ\\Publish\\API\\Repository\\Values\\Content\\Location');
690
691
        /* @var \PHPUnit_Framework_MockObject_MockObject $searchHandlerMock */
692
        $searchHandlerMock->expects($this->once())
693
            ->method('findLocations')
694
            ->with($this->equalTo($query))
695
            ->will(
696
                $this->returnValue(
697
                    new SearchResult(
698
                        array(
699
                            'searchHits' => array(new SearchHit(array('valueObject' => $spiLocation))),
700
                            'totalCount' => 1,
701
                        )
702
                    )
703
                )
704
            );
705
706
        $domainMapperMock->expects($this->once())
707
            ->method('buildLocationDomainObject')
708
            ->with($this->equalTo($spiLocation))
709
            ->will($this->returnValue($locationMock));
710
711
        $permissionsCriterionHandlerMock->expects($this->once())
712
            ->method('addPermissionsCriterion')
713
            ->with($criterionMock)
714
            ->will($this->returnValue(true));
715
716
        $result = $service->findLocations($query, array(), true);
717
718
        $this->assertEquals(
719
            new SearchResult(
720
                array(
721
                    'searchHits' => array(new SearchHit(array('valueObject' => $locationMock))),
722
                    'totalCount' => 1,
723
                )
724
            ),
725
            $result
726
        );
727
    }
728
729
    /**
730
     * Test for the findLocations() method.
731
     */
732
    public function testFindLocationsWithNoPermissionsFilter()
733
    {
734
        $repositoryMock = $this->getRepositoryMock();
735
        /** @var \eZ\Publish\SPI\Search\Handler $searchHandlerMock */
736
        $searchHandlerMock = $this->getSPIMockHandler('Search\\Handler');
737
        $domainMapperMock = $this->getDomainMapperMock();
738
        $permissionsCriterionHandlerMock = $this->getPermissionsCriterionHandlerMock();
739
        $service = new SearchService(
740
            $repositoryMock,
0 ignored issues
show
Bug introduced by
It seems like $repositoryMock defined by $this->getRepositoryMock() on line 734 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\API\Repository\Repository>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
741
            $searchHandlerMock,
742
            $domainMapperMock,
0 ignored issues
show
Bug introduced by
It seems like $domainMapperMock defined by $this->getDomainMapperMock() on line 737 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...ry\Helper\DomainMapper>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
743
            $permissionsCriterionHandlerMock,
0 ignored issues
show
Bug introduced by
It seems like $permissionsCriterionHandlerMock defined by $this->getPermissionsCriterionHandlerMock() on line 738 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...ssionsCriterionHandler>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
744
            $this->getSortClauseMapperMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getSortClauseMapperMock() targeting eZ\Publish\Core\Reposito...tSortClauseMapperMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...apper\SortClauseMapper>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
745
            array()
746
        );
747
748
        $repositoryMock->expects($this->never())->method('hasAccess');
749
750
        $serviceQuery = new LocationQuery();
751
        $handlerQuery = new LocationQuery(array('filter' => new Criterion\MatchAll(), 'limit' => 25));
752
        $spiLocation = new SPILocation();
753
        $locationMock = $this->getMockForAbstractClass('eZ\\Publish\\API\\Repository\\Values\\Content\\Location');
754
755
        /* @var \PHPUnit_Framework_MockObject_MockObject $searchHandlerMock */
756
        $searchHandlerMock->expects($this->once())
757
            ->method('findLocations')
758
            ->with($this->equalTo($handlerQuery))
759
            ->will(
760
                $this->returnValue(
761
                    new SearchResult(
762
                        array(
763
                            'searchHits' => array(new SearchHit(array('valueObject' => $spiLocation))),
764
                            'totalCount' => 1,
765
                        )
766
                    )
767
                )
768
            );
769
770
        $domainMapperMock->expects($this->once())
771
            ->method('buildLocationDomainObject')
772
            ->with($this->equalTo($spiLocation))
773
            ->will($this->returnValue($locationMock));
774
775
        $result = $service->findLocations($serviceQuery, array(), false);
776
777
        $this->assertEquals(
778
            new SearchResult(
779
                array(
780
                    'searchHits' => array(new SearchHit(array('valueObject' => $locationMock))),
781
                    'totalCount' => 1,
782
                )
783
            ),
784
            $result
785
        );
786
    }
787
788
    /**
789
     * Test for the findLocations() method.
790
     *
791
     * @expectedException \Exception
792
     * @expectedExceptionMessage Handler threw an exception
793
     */
794 View Code Duplication
    public function testFindLocationsThrowsHandlerException()
795
    {
796
        $repositoryMock = $this->getRepositoryMock();
797
        /** @var \eZ\Publish\SPI\Search\Handler $searchHandlerMock */
798
        $searchHandlerMock = $this->getSPIMockHandler('Search\\Handler');
799
        $permissionsCriterionHandlerMock = $this->getPermissionsCriterionHandlerMock();
800
801
        $service = new SearchService(
802
            $repositoryMock,
0 ignored issues
show
Bug introduced by
It seems like $repositoryMock defined by $this->getRepositoryMock() on line 796 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\API\Repository\Repository>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
803
            $searchHandlerMock,
804
            $this->getDomainMapperMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getDomainMapperMock() targeting eZ\Publish\Core\Reposito...::getDomainMapperMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...ry\Helper\DomainMapper>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
805
            $permissionsCriterionHandlerMock,
0 ignored issues
show
Bug introduced by
It seems like $permissionsCriterionHandlerMock defined by $this->getPermissionsCriterionHandlerMock() on line 799 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...ssionsCriterionHandler>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
806
            $this->getSortClauseMapperMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getSortClauseMapperMock() targeting eZ\Publish\Core\Reposito...tSortClauseMapperMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...apper\SortClauseMapper>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
807
            array()
808
        );
809
810
        /** @var \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterionMock */
811
        $criterionMock = $this
812
            ->getMockBuilder('eZ\\Publish\\API\\Repository\\Values\\Content\\Query\\Criterion')
813
            ->disableOriginalConstructor()
814
            ->getMock();
815
        $query = new LocationQuery(array('filter' => $criterionMock));
816
817
        $permissionsCriterionHandlerMock->expects($this->once())
818
            ->method('addPermissionsCriterion')
819
            ->with($criterionMock)
820
            ->will($this->throwException(new Exception('Handler threw an exception')));
821
822
        $service->findLocations($query, array(), true);
823
    }
824
825
    /**
826
     * Test for the findLocations() method.
827
     */
828
829
    /**
830
     * Test for the findContent() method.
831
     */
832
    public function testFindLocationsWithDefaultQueryValues()
833
    {
834
        $repositoryMock = $this->getRepositoryMock();
835
        /** @var \eZ\Publish\SPI\Search\Handler $searchHandlerMock */
836
        $searchHandlerMock = $this->getSPIMockHandler('Search\\Handler');
837
        $domainMapperMock = $this->getDomainMapperMock();
838
        $service = new SearchService(
839
            $repositoryMock,
0 ignored issues
show
Bug introduced by
It seems like $repositoryMock defined by $this->getRepositoryMock() on line 834 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\API\Repository\Repository>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
840
            $searchHandlerMock,
841
            $domainMapperMock,
0 ignored issues
show
Bug introduced by
It seems like $domainMapperMock defined by $this->getDomainMapperMock() on line 837 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...ry\Helper\DomainMapper>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
842
            $this->getPermissionsCriterionHandlerMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getPermissionsCriterionHandlerMock() targeting eZ\Publish\Core\Reposito...sCriterionHandlerMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...ssionsCriterionHandler>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
843
            $this->getSortClauseMapperMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getSortClauseMapperMock() targeting eZ\Publish\Core\Reposito...tSortClauseMapperMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...hService::__construct() does only seem to accept object<eZ\Publish\Core\R...apper\SortClauseMapper>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
844
            array()
845
        );
846
847
        $spiLocation = new SPILocation();
848
        $locationMock = $this->getMockForAbstractClass('eZ\\Publish\\API\\Repository\\Values\\Content\\Location');
849
        $domainMapperMock->expects($this->once())
850
            ->method('buildLocationDomainObject')
851
            ->with($this->equalTo($spiLocation))
852
            ->will($this->returnValue($locationMock));
853
854
        /* @var \PHPUnit_Framework_MockObject_MockObject $searchHandlerMock */
855
        $searchHandlerMock
856
            ->expects($this->once())
857
            ->method('findLocations')
858
            ->with(
859
                new LocationQuery(
860
                    array(
861
                        'filter' => new Criterion\MatchAll(),
862
                        'limit' => 25,
863
                    )
864
                )
865
            )
866
            ->will(
867
                $this->returnValue(
868
                    new SearchResult(
869
                        array(
870
                            'searchHits' => array(new SearchHit(array('valueObject' => $spiLocation))),
871
                            'totalCount' => 1,
872
                        )
873
                    )
874
                )
875
            );
876
877
        $result = $service->findLocations(new LocationQuery(), array(), false);
878
879
        $this->assertEquals(
880
            new SearchResult(
881
                array(
882
                    'searchHits' => array(new SearchHit(array('valueObject' => $locationMock))),
883
                    'totalCount' => 1,
884
                )
885
            ),
886
            $result
887
        );
888
    }
889
890
    /**
891
     * @return \PHPUnit_Framework_MockObject_MockObject|\eZ\Publish\Core\Repository\Helper\DomainMapper
892
     */
893 View Code Duplication
    protected function getDomainMapperMock()
894
    {
895
        if (!isset($this->domainMapperMock)) {
896
            $this->domainMapperMock = $this
897
                ->getMockBuilder('eZ\\Publish\\Core\\Repository\\Helper\\DomainMapper')
898
                ->disableOriginalConstructor()
899
                ->getMock();
900
        }
901
902
        return $this->domainMapperMock;
903
    }
904
905
    /**
906
     * @return \PHPUnit_Framework_MockObject_MockObject|\eZ\Publish\Core\Repository\PermissionsCriterionHandler
907
     */
908
    protected function getPermissionsCriterionHandlerMock()
909
    {
910
        if (!isset($this->permissionsCriterionHandlerMock)) {
911
            $this->permissionsCriterionHandlerMock = $this
912
                ->getMockBuilder('eZ\\Publish\\Core\\Repository\\PermissionsCriterionHandler')
913
                ->disableOriginalConstructor()
914
                ->getMock();
915
        }
916
917
        return $this->permissionsCriterionHandlerMock;
918
    }
919
}
920