Completed
Push — symfony3 ( 1143df...c57be8 )
by Kamil
18:42
created

TwigGridRendererSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 7
dl 0
loc 71
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 17 1
A it_is_initializable() 0 4 1
A it_is_a_grid_renderer() 0 4 1
B it_uses_twig_to_render_the_action() 0 28 1
A it_throws_an_exception_if_template_is_not_configured_for_given_action_type() 0 11 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
namespace spec\Sylius\Bundle\ResourceBundle\Grid\Renderer;
13
14
use PhpSpec\ObjectBehavior;
15
use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration;
16
use Sylius\Bundle\ResourceBundle\Grid\Parser\OptionsParserInterface;
17
use Sylius\Bundle\ResourceBundle\Grid\Renderer\TwigGridRenderer;
18
use Sylius\Bundle\ResourceBundle\Grid\View\ResourceGridView;
19
use Sylius\Component\Grid\Definition\Action;
20
use Sylius\Component\Grid\Renderer\GridRendererInterface;
21
use Symfony\Component\HttpFoundation\Request;
22
23
/**
24
 * @author Grzegorz Sadowski <[email protected]>
25
 */
26
final class TwigGridRendererSpec extends ObjectBehavior
27
{
28
    function let(
29
        GridRendererInterface $gridRenderer,
30
        \Twig_Environment $twig,
31
        OptionsParserInterface $optionsParser
32
    ) {
33
        $actionTemplates = [
34
            'link' => 'SyliusGridBundle:Action:_link.html.twig',
35
            'form' => 'SyliusGridBundle:Action:_form.html.twig',
36
        ];
37
38
        $this->beConstructedWith(
39
            $gridRenderer,
40
            $twig,
41
            $optionsParser,
42
            $actionTemplates
43
        );
44
    }
45
46
    function it_is_initializable()
47
    {
48
        $this->shouldHaveType(TwigGridRenderer::class);
49
    }
50
51
    function it_is_a_grid_renderer()
52
    {
53
        $this->shouldImplement(GridRendererInterface::class);
54
    }
55
56
    function it_uses_twig_to_render_the_action(
57
        \Twig_Environment $twig,
58
        OptionsParserInterface $optionsParser,
59
        ResourceGridView $gridView,
60
        Action $action,
61
        RequestConfiguration $requestConfiguration,
62
        Request $request
63
    ) {
64
        $action->getType()->willReturn('link');
65
        $action->getOptions()->willReturn([]);
66
67
        $gridView->getRequestConfiguration()->willReturn($requestConfiguration);
68
        $requestConfiguration->getRequest()->willReturn($request);
69
70
        $optionsParser->parseOptions([], $request, null)->shouldBeCalled();
71
72
        $twig
73
            ->render('SyliusGridBundle:Action:_link.html.twig', [
74
                'grid' => $gridView,
75
                'action' => $action,
76
                'data' => null,
77
                'options' => [],
78
            ])
79
            ->willReturn('<a href="#">Action!</a>')
80
        ;
81
82
        $this->renderAction($gridView, $action)->shouldReturn('<a href="#">Action!</a>');
83
    }
84
85
    function it_throws_an_exception_if_template_is_not_configured_for_given_action_type(
86
        ResourceGridView $gridView,
87
        Action $action
88
    ) {
89
        $action->getType()->willReturn('foo');
90
91
        $this
92
            ->shouldThrow(new \InvalidArgumentException('Missing template for action type "foo".'))
93
            ->during('renderAction', [$gridView, $action])
94
        ;
95
    }
96
}
97