Completed
Push — sonata-block-4 ( 430eec...7b4499 )
by Kamil
66:32 queued 45:06
created

TemplateEventTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 54
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A it_renders_template_events_blocks() 0 13 1
A it_renders_debug_info_in_html_comments_while_rendering_in_test_environment() 0 13 1
A it_passes_context_defined_in_template_block_configuration_during_rendering() 0 10 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sylius\Bundle\UiBundle\Tests\Functional;
15
16
use PHPUnit\Framework\Assert;
17
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
18
use Twig\Environment;
19
20
final class TemplateEventTest extends KernelTestCase
21
{
22
    /** @var Environment */
23
    private $twig;
24
25
    protected function setUp(): void
26
    {
27
        self::bootKernel();
28
29
        $this->twig = self::$container->get('twig');
30
    }
31
32
    /** @test */
33
    public function it_renders_template_events_blocks(): void
34
    {
35
        // See Kernel.php for the configuration resulting in those lines
36
        $expectedLines = [
37
            'First block',
38
            'Second block',
39
            'Third block',
40
            'The king is dead, long live the king!',
41
        ];
42
        $renderedLines = array_values(array_filter(explode("\n", $this->twig->render('templateEvents.txt.twig'))));
43
44
        Assert::assertSame($expectedLines, $renderedLines);
45
    }
46
47
    /** @test */
48
    public function it_renders_debug_info_in_html_comments_while_rendering_in_test_environment(): void
49
    {
50
        // See Kernel.php for the configuration resulting in those lines
51
        $expectedLines = [
52
            '<!-- event name: "event", block name: "first", template: "blocks/html/first.html.twig", priority: 5 -->',
53
            '<p id="first">First block</p>',
54
            '<!-- event name: "event", block name: "context", template: "blocks/html/context.html.twig", priority: -5 -->',
55
            '<p class="context">The king is dead, long live the king!</p>',
56
        ];
57
        $renderedLines = array_values(array_filter(explode("\n", $this->twig->render('templateEvents.html.twig'))));
58
59
        Assert::assertSame($expectedLines, $renderedLines);
60
    }
61
62
    /** @test */
63
    public function it_passes_context_defined_in_template_block_configuration_during_rendering(): void
64
    {
65
        // See Kernel.php for the configuration resulting in those lines
66
        $expectedLines = [
67
            'Block: option1=foo, option2=baz',
68
        ];
69
        $renderedLines = array_values(array_filter(explode("\n", $this->twig->render('contextTemplateBlock.txt.twig'))));
70
71
        Assert::assertSame($expectedLines, $renderedLines);
72
    }
73
}
74