Completed
Push — 1.0-reliable-behat ( 67387b )
by Kamil
55:32 queued 21:17
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
final class TwigGridRendererSpec extends ObjectBehavior
25
{
26
    function let(
27
        GridRendererInterface $gridRenderer,
28
        \Twig_Environment $twig,
29
        OptionsParserInterface $optionsParser
30
    ): void {
31
        $actionTemplates = [
32
            'link' => 'SyliusGridBundle:Action:_link.html.twig',
33
            'form' => 'SyliusGridBundle:Action:_form.html.twig',
34
        ];
35
36
        $this->beConstructedWith(
37
            $gridRenderer,
38
            $twig,
39
            $optionsParser,
40
            $actionTemplates
41
        );
42
    }
43
44
    function it_is_a_grid_renderer(): void
45
    {
46
        $this->shouldImplement(GridRendererInterface::class);
47
    }
48
49
    function it_uses_twig_to_render_the_action(
50
        \Twig_Environment $twig,
51
        OptionsParserInterface $optionsParser,
52
        ResourceGridView $gridView,
53
        Action $action,
54
        RequestConfiguration $requestConfiguration,
55
        Request $request
56
    ): void {
57
        $action->getType()->willReturn('link');
58
        $action->getOptions()->willReturn([]);
59
60
        $gridView->getRequestConfiguration()->willReturn($requestConfiguration);
61
        $requestConfiguration->getRequest()->willReturn($request);
62
63
        $optionsParser->parseOptions([], $request, null)->shouldBeCalled();
64
65
        $twig
66
            ->render('SyliusGridBundle:Action:_link.html.twig', [
67
                'grid' => $gridView,
68
                'action' => $action,
69
                'data' => null,
70
                'options' => [],
71
            ])
72
            ->willReturn('<a href="#">Action!</a>')
73
        ;
74
75
        $this->renderAction($gridView, $action)->shouldReturn('<a href="#">Action!</a>');
76
    }
77
78
    function it_throws_an_exception_if_template_is_not_configured_for_given_action_type(
79
        ResourceGridView $gridView,
80
        Action $action
81
    ): void {
82
        $action->getType()->willReturn('foo');
83
84
        $this
85
            ->shouldThrow(new \InvalidArgumentException('Missing template for action type "foo".'))
86
            ->during('renderAction', [$gridView, $action])
87
        ;
88
    }
89
}
90