Completed
Push — master ( 52cd2c...047880 )
by Kamil
47:26 queued 26:32
created

TemplateBlockRendererSpec   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 63
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_a_template_block_renderer() 0 4 1
A it_renders_a_template_block() 0 10 1
A it_merges_template_block_context_with_passed_context() 0 10 1
A it_renders_html_debug_comment_prepending_the_comment_if_in_debug_mode_rendering_html_template() 0 15 1
A it_renders_html_debug_comment_prepending_the_comment_if_not_in_debug_mode_rendering_html_template() 0 12 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 spec\Sylius\Bundle\UiBundle\Renderer;
15
16
use PhpSpec\ObjectBehavior;
17
use Sylius\Bundle\UiBundle\Registry\TemplateBlock;
18
use Sylius\Bundle\UiBundle\Renderer\TemplateBlockRendererInterface;
19
use Twig\Environment;
20
21
final class TemplateBlockRendererSpec extends ObjectBehavior
22
{
23
    function let(Environment $twig): void
24
    {
25
        $this->beConstructedWith($twig, false);
26
    }
27
28
    function it_is_a_template_block_renderer(): void
29
    {
30
        $this->shouldImplement(TemplateBlockRendererInterface::class);
31
    }
32
33
    function it_renders_a_template_block(Environment $twig): void
34
    {
35
        $twig->render('block.txt.twig', ['foo' => 'bar'])->willReturn('Block content');
36
37
        $this->render(
38
            'event_name',
39
            new TemplateBlock('block_name', 'block.txt.twig', [], 0, true),
40
            ['foo' => 'bar']
41
        )->shouldReturn('Block content');
42
    }
43
44
    function it_merges_template_block_context_with_passed_context(Environment $twig): void
45
    {
46
        $twig->render('block.txt.twig', ['sample' => 'Hello', 'switch' => true])->willReturn('Block content');
47
48
        $this->render(
49
            'event_name',
50
            new TemplateBlock('block_name', 'block.txt.twig', ['sample' => 'Hi', 'switch' => true], 0, true),
51
            ['sample' => 'Hello']
52
        )->shouldReturn('Block content');
53
    }
54
55
    function it_renders_html_debug_comment_prepending_the_comment_if_in_debug_mode_rendering_html_template(Environment $twig): void
56
    {
57
        $this->beConstructedWith($twig, true);
58
59
        $twig->render('block.html.twig', ['foo' => 'bar'])->willReturn('Block content');
60
61
        $this->render(
62
            'event_name',
63
            new TemplateBlock('block_name', 'block.html.twig', [], 0, true),
64
            ['foo' => 'bar']
65
        )->shouldReturn(
66
            '<!-- event name: "event_name", block name: "block_name", template: "block.html.twig", priority: 0 -->' . "\n" .
67
            'Block content'
68
        );
69
    }
70
71
    function it_renders_html_debug_comment_prepending_the_comment_if_not_in_debug_mode_rendering_html_template(Environment $twig): void
72
    {
73
        $this->beConstructedWith($twig, false);
74
75
        $twig->render('block.html.twig', ['foo' => 'bar'])->willReturn('Block content');
76
77
        $this->render(
78
            'event_name',
79
            new TemplateBlock('block_name', 'block.html.twig', [], 0, true),
80
            ['foo' => 'bar']
81
        )->shouldReturn('Block content');
82
    }
83
}
84