|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
4
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
5
|
|
|
*/ |
|
6
|
|
|
namespace eZ\Publish\Core\REST\Server\Tests\Output\PathExpansion\ValueLoaders; |
|
7
|
|
|
|
|
8
|
|
|
use eZ\Publish\Core\REST\Server\Output\PathExpansion\ValueLoaders\UniqueUriValueLoader; |
|
9
|
|
|
use stdClass; |
|
10
|
|
|
|
|
11
|
|
|
class UniqueUriValueLoaderTest extends \PHPUnit_Framework_TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
private $innerLoaderMock; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @expectedException \eZ\Publish\Core\REST\Server\Output\PathExpansion\Exceptions\MultipleValueLoadException |
|
17
|
|
|
*/ |
|
18
|
|
|
public function testLoad() |
|
19
|
|
|
{ |
|
20
|
|
|
$loader = $this->buildLoader(); |
|
21
|
|
|
|
|
22
|
|
|
$returnValue = new stdClass(); |
|
23
|
|
|
|
|
24
|
|
|
$this->getInnerLoaderMock() |
|
25
|
|
|
->expects($this->exactly(2)) |
|
26
|
|
|
->method('load') |
|
27
|
|
|
->withConsecutive( |
|
28
|
|
|
['/doctors/david-tenant', null], |
|
29
|
|
|
['/doctors/david-tenant', 'application/other-type'] |
|
30
|
|
|
) |
|
31
|
|
|
->will($this->returnValue($returnValue)); |
|
32
|
|
|
|
|
33
|
|
|
self::assertEquals($returnValue, $loader->load('/doctors/david-tenant')); |
|
34
|
|
|
self::assertEquals($returnValue, $loader->load('/doctors/david-tenant', 'application/other-type')); |
|
35
|
|
|
$loader->load('/doctors/david-tenant'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @return \eZ\Publish\Core\REST\Server\Output\PathExpansion\ValueLoaders\UniqueUriValueLoader |
|
40
|
|
|
*/ |
|
41
|
|
|
protected function buildLoader() |
|
42
|
|
|
{ |
|
43
|
|
|
return new UniqueUriValueLoader($this->getInnerLoaderMock()); |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|\eZ\Publish\Core\REST\Server\Output\PathExpansion\ValueLoaders\UriValueLoader |
|
48
|
|
|
*/ |
|
49
|
|
|
protected function getInnerLoaderMock() |
|
50
|
|
|
{ |
|
51
|
|
|
if (!isset($this->innerLoaderMock)) { |
|
52
|
|
|
$this->innerLoaderMock = $this |
|
53
|
|
|
->getMockBuilder('eZ\Publish\Core\REST\Server\Output\PathExpansion\ValueLoaders\UriValueLoader') |
|
54
|
|
|
->getMock(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return $this->innerLoaderMock; |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
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.