Completed
Pull Request — master (#37)
by Daniel
04:38
created

TwigRendererTest::provideViews()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 52
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 52
rs 9.4929
c 0
b 0
f 0
cc 1
eloc 23
nc 1
nop 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
namespace Psi\Bridge\ContentType\Twig\Tests\Functional;
4
5
use Psi\Bridge\ContentType\Twig\ContentTypeExtension;
6
use Psi\Bridge\ContentType\Twig\TwigRenderer;
7
use Psi\Component\ContentType\Standard\View\ScalarView;
8
use Psi\Component\ContentType\View\View;
9
use Psi\Component\ContentType\Standard\View\ScalarType;
10
use Psi\Component\ContentType\Standard\View\ObjectType;
11
use Psi\Component\ContentType\Standard\View\CollectionType;
12
use Psi\Component\ContentType\Standard\View\NullType;
13
use Psi\Component\ContentType\Tests\Functional\Example\Model\Article;
14
15
class TwigRendererTest extends TestCase
16
{
17
    private $renderer;
18
19 View Code Duplication
    public function setUp()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
    {
21
        $container = $this->getContainer([
22
            'mapping' => [
23
                Article::class => [
24
                    'alias' => 'article',
25
                    'fields' => [
26
                        'title' => [
27
                            'type' => 'text',
28
                        ],
29
                    ],
30
                ],
31
            ],
32
        ]);
33
        $this->renderer = $container->get('psi_content_type.view.twig.renderer');
34
        $this->viewFactory = $container->get('psi_content_type.view.factory');
0 ignored issues
show
Bug introduced by
The property viewFactory does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
35
    }
36
37
    /**
38
     * It should renderer a views.
39
     *
40
     * @dataProvider provideViews
41
     */
42
    public function testRender($viewType, $data, array $options, $expected)
43
    {
44
        $view = $this->viewFactory->create($viewType, $data, $options);
45
        $output = $this->renderer->render($view);
46
        $this->assertEquals($expected, $output);
47
    }
48
49
    public function provideViews()
50
    {
51
        $article = new Article();
52
        $article->title = "Hello";
53
        return [
54
            [
55
                ScalarType::class,
56
                'hello',
57
                [],
58
                'hello',
59
            ],
60
            [
61
                ObjectType::class,
62
                $article,
63
                [],
64
                <<<'EOT'
65
    <div>
66
        Hello
67
    </div>
68
69
EOT
70
            ],
71
            [
72
                CollectionType::class,
73
                [
74
                    'hello',
75
                    'goodbye',
76
                ],
77
                [
78
                    'field_type' => 'text',
79
                    'field_options' => [],
80
                ],
81
                <<<'EOT'
82
<ul>
83
            <li>
84
            hello
85
        </li>
86
            <li>
87
            goodbye
88
        </li>
89
    </ul>
90
91
EOT
92
            ],
93
            [
94
                NullType::class,
95
                'nothing',
96
                [],
97
                ''
98
            ]
99
        ];
100
    }
101
}
102