Completed
Push — EZP-30427 ( 70aaad...6c786c )
by
unknown
20:55
created

ContentViewTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 71
Duplicated Lines 11.27 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 8
loc 71
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 2

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstruct() 0 6 1
A constructProvider() 0 20 1
A testConstructFail() 0 4 1
A constructFailProvider() 8 8 1
A createViewUnderTest() 0 4 1
A getAlwaysAvailableParams() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Core\MVC\Symfony\View\Tests;
10
11
use eZ\Publish\Core\MVC\Symfony\View\ContentView;
12
use eZ\Publish\Core\MVC\Symfony\View\View;
13
14
/**
15
 * @group mvc
16
 */
17
class ContentViewTest extends AbstractViewTest
18
{
19
    /**
20
     * Params that are always returned by this view.
21
     * @var array
22
     */
23
    private $valueParams = ['content' => null];
24
25
    /**
26
     * @dataProvider constructProvider
27
     * @covers \eZ\Publish\Core\MVC\Symfony\View\ContentView::__construct
28
     * @covers \eZ\Publish\Core\MVC\Symfony\View\ContentView::getTemplateIdentifier
29
     * @covers \eZ\Publish\Core\MVC\Symfony\View\ContentView::getParameters
30
     */
31
    public function testConstruct($templateIdentifier, array $params)
32
    {
33
        $contentView = new ContentView($templateIdentifier, $params);
34
        self::assertSame($templateIdentifier, $contentView->getTemplateIdentifier());
35
        self::assertSame($this->valueParams + $params, $contentView->getParameters());
36
    }
37
38
    public function constructProvider()
39
    {
40
        return [
41
            ['some:valid:identifier', ['foo' => 'bar']],
42
            ['another::identifier', []],
43
            ['oops:i_did_it:again', ['singer' => 'Britney Spears']],
44
            [
45
                function () {
46
                    return true;
47
                },
48
                [],
49
            ],
50
            [
51
                function () {
52
                    return true;
53
                },
54
                ['truc' => 'muche'],
55
            ],
56
        ];
57
    }
58
59
    /**
60
     * @dataProvider constructFailProvider
61
     * @expectedException \eZ\Publish\Core\Base\Exceptions\InvalidArgumentType
62
     * @covers \eZ\Publish\Core\MVC\Symfony\View\ContentView::__construct
63
     */
64
    public function testConstructFail($templateIdentifier)
65
    {
66
        new ContentView($templateIdentifier);
67
    }
68
69 View Code Duplication
    public function constructFailProvider()
70
    {
71
        return [
72
            [123],
73
            [new \stdClass()],
74
            [[1, 2, 3]],
75
        ];
76
    }
77
78
    protected function createViewUnderTest($template = null, array $parameters = [], $viewType = 'full'): View
79
    {
80
        return new ContentView($template, $parameters, $viewType);
81
    }
82
83
    protected function getAlwaysAvailableParams(): array
84
    {
85
        return $this->valueParams;
86
    }
87
}
88