Completed
Push — EZP-30470 ( 9c9496 )
by
unknown
38:05 queued 16:21
created

VersionBuilderTest::providerForTestBuild()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 58

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 58
rs 8.9163
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace eZ\Publish\SPI\Tests\Limitation\Target\Builder;
10
11
use eZ\Publish\API\Repository\Values\Content\Field;
12
use eZ\Publish\API\Repository\Values\Content\VersionInfo;
13
use eZ\Publish\SPI\Limitation\Target\Builder\VersionBuilder;
14
use eZ\Publish\SPI\Limitation\Target;
15
use PHPUnit\Framework\TestCase;
16
17
/**
18
 * @covers \eZ\Publish\SPI\Limitation\Target\Builder\VersionBuilder
19
 */
20
class VersionBuilderTest extends TestCase
21
{
22
    /**
23
     * Data provider for testBuild.
24
     *
25
     * @see testBuild
26
     *
27
     * @return array
28
     */
29
    public function providerForTestBuild(): array
30
    {
31
        $versionStatuses = [
32
            VersionInfo::STATUS_DRAFT,
33
            VersionInfo::STATUS_PUBLISHED,
34
            VersionInfo::STATUS_ARCHIVED,
35
        ];
36
37
        $data = [];
38
        foreach ($versionStatuses as $versionStatus) {
39
            $languagesList = ['ger-DE', 'eng-US', 'eng-GB'];
40
            $contentTypeIdsList = ['1', '2'];
41
            $initialLanguageCode = 'eng-US';
42
            $fields = [
43
                new Field(['languageCode' => 'ger-DE']),
44
                new Field(['languageCode' => 'ger-DE']),
45
                new Field(['languageCode' => 'eng-US']),
46
            ];
47
            $updateTranslationsLanguageCodes = ['ger-DE', 'eng-US'];
48
49
            $data[] = [
50
                new Target\Version(
51
                    [
52
                        'newStatus' => $versionStatus,
53
                        'allLanguageCodesList' => $languagesList,
54
                        'allContentTypeIdsList' => $contentTypeIdsList,
55
                        'forUpdateLanguageCodesList' => $updateTranslationsLanguageCodes,
56
                        'forUpdateInitialLanguageCode' => $initialLanguageCode,
57
                    ]
58
                ),
59
                $versionStatus,
60
                $initialLanguageCode,
61
                $fields,
62
                $languagesList,
63
                $contentTypeIdsList,
64
            ];
65
66
            // no published content
67
            $data[] = [
68
                new Target\Version(
69
                    [
70
                        'newStatus' => $versionStatus,
71
                        'allLanguageCodesList' => $languagesList,
72
                        'allContentTypeIdsList' => $contentTypeIdsList,
73
                        'forUpdateLanguageCodesList' => $updateTranslationsLanguageCodes,
74
                        'forUpdateInitialLanguageCode' => $initialLanguageCode,
75
                    ]
76
                ),
77
                $versionStatus,
78
                $initialLanguageCode,
79
                $fields,
80
                $languagesList,
81
                $contentTypeIdsList,
82
            ];
83
        }
84
85
        return $data;
86
    }
87
88
    /**
89
     * @covers       \eZ\Publish\SPI\Limitation\Target\Builder\VersionBuilder::build
90
     *
91
     * @dataProvider providerForTestBuild
92
     *
93
     * @param \eZ\Publish\SPI\Limitation\Target\Version $expectedTargetVersion
94
     * @param int $newStatus
95
     * @param string $initialLanguageCode
96
     * @param \eZ\Publish\API\Repository\Values\Content\Field[] $newFields
97
     * @param string[] $languagesList
98
     * @param string[] $contentTypeIdsList
99
     *
100
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
101
     */
102
    public function testBuild(
103
        Target\Version $expectedTargetVersion,
104
        int $newStatus,
105
        string $initialLanguageCode,
106
        array $newFields,
107
        array $languagesList,
108
        array $contentTypeIdsList
109
    ): void {
110
        $versionBuilder = new VersionBuilder();
111
        $versionBuilder
112
            ->changeStatusTo($newStatus)
113
            ->updateFieldsTo($initialLanguageCode, $newFields)
114
            ->translateToAnyLanguageOf($languagesList)
115
            ->createFromAnyContentTypeOf($contentTypeIdsList);
116
117
        self::assertInstanceOf(VersionBuilder::class, $versionBuilder);
118
        self::assertEquals($expectedTargetVersion, $versionBuilder->build());
119
    }
120
}
121