Completed
Push — master ( 2d5ed5...57ba8c )
by Daniel
12s
created

TwigRendererTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 10

Duplication

Lines 17
Ratio 100 %

Importance

Changes 0
Metric Value
dl 17
loc 17
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
3
namespace Psi\Bridge\ContentType\Twig\Tests\Functional;
4
5
use Psi\Component\ContentType\Standard\View\CollectionType;
6
use Psi\Component\ContentType\Standard\View\NullType;
7
use Psi\Component\ContentType\Standard\View\ObjectType;
8
use Psi\Component\ContentType\Standard\View\ScalarType;
9
use Psi\Component\ContentType\Tests\Functional\Example\Model\Article;
10
11
class TwigRendererTest extends TestCase
12
{
13
    private $renderer;
14
    private $viewFactory;
15
16 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...
17
    {
18
        $container = $this->getContainer([
19
            'mapping' => [
20
                Article::class => [
21
                    'alias' => 'article',
22
                    'fields' => [
23
                        'title' => [
24
                            'type' => 'text',
25
                        ],
26
                    ],
27
                ],
28
            ],
29
        ]);
30
        $this->renderer = $container->get('psi_content_type.view.twig.renderer');
31
        $this->viewFactory = $container->get('psi_content_type.view.factory');
32
    }
33
34
    /**
35
     * It should renderer a views.
36
     *
37
     * @dataProvider provideViews
38
     */
39
    public function testRender($viewType, $data, array $options, $expected)
40
    {
41
        $view = $this->viewFactory->create($viewType, $data, $options);
42
        $output = $this->renderer->render($view);
43
        $this->assertEquals($expected, $output);
44
    }
45
46
    public function provideViews()
47
    {
48
        $article = new Article();
49
        $article->title = 'Hello';
50
51
        return [
52
            [
53
                ScalarType::class,
54
                'hello',
55
                [],
56
                'hello',
57
            ],
58
            [
59
                ObjectType::class,
60
                $article,
61
                [],
62
                <<<'EOT'
63
    <div>
64
        Hello
65
    </div>
66
67
EOT
68
            ],
69
            [
70
                CollectionType::class,
71
                [
72
                    'hello',
73
                    'goodbye',
74
                ],
75
                [
76
                    'field_type' => 'text',
77
                    'field_options' => [],
78
                ],
79
                <<<'EOT'
80
<ul>
81
            <li>
82
            hello
83
        </li>
84
            <li>
85
            goodbye
86
        </li>
87
    </ul>
88
89
EOT
90
            ],
91
            [
92
                NullType::class,
93
                'nothing',
94
                [],
95
                '',
96
            ],
97
        ];
98
    }
99
}
100