Completed
Push — 1.0-partially-shipped ( b5b315 )
by Kamil
58:43 queued 31:11
created

TwigGridRendererSpec   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 7
dl 0
loc 66
rs 10
c 0
b 0
f 0

4 Methods

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