Completed
Push — spi_versionInfo_languageCode ( ce7a20 )
by André
17:56
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\Language as SPILanguage;
15
use eZ\Publish\SPI\Persistence\Content\VersionInfo as SPIVersionInfo;
16
use eZ\Publish\SPI\Persistence\Content\ContentInfo as SPIContentInfo;
17
18
/**
19
 * Mock test case for internal DomainMapper.
20
 */
21
class DomainMapperTest extends BaseServiceMockTest
22
{
23
    /**
24
     * @covers \eZ\Publish\Core\Repository\Helper\DomainMapper::buildVersionInfoDomainObject
25
     * @dataProvider providerForBuildVersionInfo
26
     */
27
    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...
28
    {
29
        $languageHandlerMock = $this->getLanguageHandlerMock();
30
        $languageHandlerMock->expects($this->never())->method('load');
31
32
        $versionInfo = $this->getDomainMapper()->buildVersionInfoDomainObject($spiVersionInfo);
33
        $this->assertInstanceOf('eZ\\Publish\\Core\\Repository\\Values\\Content\\VersionInfo', $versionInfo);
34
35
        foreach ($expected as $expectedProperty => $expectedValue) {
36
            $this->assertAttributeSame(
37
                $expectedValue,
38
                $expectedProperty,
39
                $versionInfo
40
            );
41
        }
42
    }
43
44
    public function providerForBuildVersionInfo()
45
    {
46
        return array(
47
            array(
48
                new SPIVersionInfo(
49
                    array(
50
                        'status' => 44,
51
                        'contentInfo' => new SPIContentInfo(),
52
                    )
53
                ),
54
                array(),
55
                array('status' => APIVersionInfo::STATUS_DRAFT),
56
            ),
57
            array(
58
                new SPIVersionInfo(
59
                    array(
60
                        'status' => SPIVersionInfo::STATUS_DRAFT,
61
                        'contentInfo' => new SPIContentInfo(),
62
                    )
63
                ),
64
                array(),
65
                array('status' => APIVersionInfo::STATUS_DRAFT),
66
            ),
67
            array(
68
                new SPIVersionInfo(
69
                    array(
70
                        'status' => SPIVersionInfo::STATUS_PENDING,
71
                        'contentInfo' => new SPIContentInfo(),
72
                    )
73
                ),
74
                array(),
75
                array('status' => APIVersionInfo::STATUS_DRAFT),
76
            ),
77
            array(
78
                new SPIVersionInfo(
79
                    array(
80
                        'status' => SPIVersionInfo::STATUS_ARCHIVED,
81
                        'contentInfo' => new SPIContentInfo(),
82
                        'languageCodes' => array('eng-GB', 'nor-NB', 'fre-FR'),
83
                    )
84
                ),
85
                array(1 => 'eng-GB', 3 => 'nor-NB', 5 => 'fre-FR'),
86
                array(
87
                    'status' => APIVersionInfo::STATUS_ARCHIVED,
88
                    'languageCodes' => array('eng-GB', 'nor-NB', 'fre-FR'),
89
                ),
90
            ),
91
            array(
92
                new SPIVersionInfo(
93
                    array(
94
                        'status' => SPIVersionInfo::STATUS_PUBLISHED,
95
                        'contentInfo' => new SPIContentInfo(),
96
                    )
97
                ),
98
                array(),
99
                array('status' => APIVersionInfo::STATUS_PUBLISHED),
100
            ),
101
        );
102
    }
103
104
    /**
105
     * Returns DomainMapper.
106
     *
107
     * @return \eZ\Publish\Core\Repository\Helper\DomainMapper
108
     */
109
    protected function getDomainMapper()
110
    {
111
        return new DomainMapper(
112
            $this->getPersistenceMockHandler('Content\\Handler'),
113
            $this->getPersistenceMockHandler('Content\\Location\\Handler'),
114
            $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...
115
            $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...
116
            $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...
117
        );
118
    }
119
120
    /**
121
     * @return \eZ\Publish\SPI\Persistence\Content\Language\Handler|\PHPUnit_Framework_MockObject_MockObject
122
     */
123
    protected function getLanguageHandlerMock()
124
    {
125
        return $this->getPersistenceMockHandler('Content\\Language\\Handler');
126
    }
127
128
    /**
129
     * @return \eZ\Publish\SPI\Persistence\Content\Type\Handler|\PHPUnit_Framework_MockObject_MockObject
130
     */
131
    protected function getTypeHandlerMock()
132
    {
133
        return $this->getPersistenceMockHandler('Content\\Type\\Handler');
134
    }
135
}
136