Completed
Push — ezp26352-skip_csrf_check_on_re... ( 19f37a )
by
unknown
36:29
created

UniqueUriValueLoaderTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testLoad() 0 19 1
A buildLoader() 0 4 1
A getInnerLoaderMock() 0 10 2
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());
0 ignored issues
show
Bug introduced by
It seems like $this->getInnerLoaderMock() targeting eZ\Publish\Core\REST\Ser...t::getInnerLoaderMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\REST\Ser...ueLoader::__construct() does only seem to accept object<eZ\Publish\Core\R...Loaders\UriValueLoader>, 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...
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