Completed
Push — master ( b22f08...115366 )
by André
34:29 queued 20:05
created

DomainMapperTest::testBuildVersionInfo()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 3
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File contains: eZ\Publish\Core\Repository\Tests\Service\Mock\DomainMapperTest 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\API\Repository\Values\Content\VersionInfo as APIVersionInfo;
12
use eZ\Publish\Core\Repository\Tests\Service\Mock\Base as BaseServiceMockTest;
13
use eZ\Publish\Core\Repository\Helper\DomainMapper;
14
use eZ\Publish\SPI\Persistence\Content\VersionInfo as SPIVersionInfo;
15
use eZ\Publish\SPI\Persistence\Content\ContentInfo as SPIContentInfo;
16
17
/**
18
 * Mock test case for internal DomainMapper.
19
 */
20
class DomainMapperTest extends BaseServiceMockTest
21
{
22
    /**
23
     * @covers \eZ\Publish\Core\Repository\Helper\DomainMapper::buildVersionInfoDomainObject
24
     * @dataProvider providerForBuildVersionInfo
25
     */
26
    public function testBuildVersionInfo(SPIVersionInfo $spiVersionInfo, array $languages, array $expected)
0 ignored issues
show
Unused Code introduced by
The parameter $languages is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
27
    {
28
        $languageHandlerMock = $this->getLanguageHandlerMock();
29
        $languageHandlerMock->expects($this->never())->method('load');
30
31
        $versionInfo = $this->getDomainMapper()->buildVersionInfoDomainObject($spiVersionInfo);
32
        $this->assertInstanceOf('eZ\\Publish\\Core\\Repository\\Values\\Content\\VersionInfo', $versionInfo);
33
34
        foreach ($expected as $expectedProperty => $expectedValue) {
35
            $this->assertAttributeSame(
36
                $expectedValue,
37
                $expectedProperty,
38
                $versionInfo
39
            );
40
        }
41
    }
42
43
    public function providerForBuildVersionInfo()
44
    {
45
        return array(
46
            array(
47
                new SPIVersionInfo(
48
                    array(
49
                        'status' => 44,
50
                        'contentInfo' => new SPIContentInfo(),
51
                    )
52
                ),
53
                array(),
54
                array('status' => APIVersionInfo::STATUS_DRAFT),
55
            ),
56
            array(
57
                new SPIVersionInfo(
58
                    array(
59
                        'status' => SPIVersionInfo::STATUS_DRAFT,
60
                        'contentInfo' => new SPIContentInfo(),
61
                    )
62
                ),
63
                array(),
64
                array('status' => APIVersionInfo::STATUS_DRAFT),
65
            ),
66
            array(
67
                new SPIVersionInfo(
68
                    array(
69
                        'status' => SPIVersionInfo::STATUS_PENDING,
70
                        'contentInfo' => new SPIContentInfo(),
71
                    )
72
                ),
73
                array(),
74
                array('status' => APIVersionInfo::STATUS_DRAFT),
75
            ),
76
            array(
77
                new SPIVersionInfo(
78
                    array(
79
                        'status' => SPIVersionInfo::STATUS_ARCHIVED,
80
                        'contentInfo' => new SPIContentInfo(),
81
                        'languageCodes' => array('eng-GB', 'nor-NB', 'fre-FR'),
82
                    )
83
                ),
84
                array(1 => 'eng-GB', 3 => 'nor-NB', 5 => 'fre-FR'),
85
                array(
86
                    'status' => APIVersionInfo::STATUS_ARCHIVED,
87
                    'languageCodes' => array('eng-GB', 'nor-NB', 'fre-FR'),
88
                ),
89
            ),
90
            array(
91
                new SPIVersionInfo(
92
                    array(
93
                        'status' => SPIVersionInfo::STATUS_PUBLISHED,
94
                        'contentInfo' => new SPIContentInfo(),
95
                    )
96
                ),
97
                array(),
98
                array('status' => APIVersionInfo::STATUS_PUBLISHED),
99
            ),
100
        );
101
    }
102
103
    /**
104
     * Returns DomainMapper.
105
     *
106
     * @return \eZ\Publish\Core\Repository\Helper\DomainMapper
107
     */
108
    protected function getDomainMapper()
109
    {
110
        return new DomainMapper(
111
            $this->getPersistenceMockHandler('Content\\Handler'),
112
            $this->getPersistenceMockHandler('Content\\Location\\Handler'),
113
            $this->getTypeHandlerMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getTypeHandlerMock() targeting eZ\Publish\Core\Reposito...t::getTypeHandlerMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...inMapper::__construct() does only seem to accept object<eZ\Publish\SPI\Pe...e\Content\Type\Handler>, 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...
114
            $this->getLanguageHandlerMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getLanguageHandlerMock() targeting eZ\Publish\Core\Reposito...etLanguageHandlerMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...inMapper::__construct() does only seem to accept object<eZ\Publish\SPI\Pe...ntent\Language\Handler>, 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...
115
            $this->getFieldTypeRegistryMock()
0 ignored issues
show
Bug introduced by
It seems like $this->getFieldTypeRegistryMock() targeting eZ\Publish\Core\Reposito...FieldTypeRegistryMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Reposito...inMapper::__construct() does only seem to accept object<eZ\Publish\Core\R...lper\FieldTypeRegistry>, 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...
116
        );
117
    }
118
119
    /**
120
     * @return \eZ\Publish\SPI\Persistence\Content\Language\Handler|\PHPUnit_Framework_MockObject_MockObject
121
     */
122
    protected function getLanguageHandlerMock()
123
    {
124
        return $this->getPersistenceMockHandler('Content\\Language\\Handler');
125
    }
126
127
    /**
128
     * @return \eZ\Publish\SPI\Persistence\Content\Type\Handler|\PHPUnit_Framework_MockObject_MockObject
129
     */
130
    protected function getTypeHandlerMock()
131
    {
132
        return $this->getPersistenceMockHandler('Content\\Type\\Handler');
133
    }
134
}
135