Completed
Push — refonte ( 64e01a...7173e3 )
by Arnaud
03:31
created

testRespondWithoutSubmittedForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 40
rs 9.28
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace LAG\AdminBundle\Tests\AdminBundle\Action\Responder;
4
5
use LAG\AdminBundle\Action\Configuration\ActionConfiguration;
6
use LAG\AdminBundle\Action\Responder\DeleteResponder;
7
use LAG\AdminBundle\Admin\AdminInterface;
8
use LAG\AdminBundle\Admin\Configuration\AdminConfiguration;
9
use LAG\AdminBundle\Tests\AdminTestBase;
10
use Symfony\Component\Form\FormInterface;
11
use Symfony\Component\HttpFoundation\RedirectResponse;
12
use Symfony\Component\HttpFoundation\Response;
13
use Symfony\Component\Routing\RouterInterface;
14
use Twig_Environment;
15
16
class DeleteResponderTest extends AdminTestBase
17
{
18 View Code Duplication
    public function testRespond()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
    {
20
        $routing = $this->getMockWithoutConstructor(RouterInterface::class);
21
        $routing
22
            ->expects($this->atLeastOnce())
23
            ->method('generate')
24
            ->with('my_little_admin.list')
25
            ->willReturn('http://test.fr')
26
        ;
27
    
28
        $configuration = $this->getMockWithoutConstructor(ActionConfiguration::class);
29
        $configuration
30
            ->expects($this->atLeastOnce())
31
            ->method('getParameter')
32
            ->willReturnMap([
33
                ['template', 'my_template.twig'],
34
            ])
35
        ;
36
        
37
        $adminConfiguration = $this->getMockWithoutConstructor(AdminConfiguration::class);
38
        $adminConfiguration
39
            ->expects($this->once())
40
            ->method('isResolved')
41
            ->willReturn(true)
42
        ;
43
        $adminConfiguration
44
            ->expects($this->atLeastOnce())
45
            ->method('getParameter')
46
            ->willReturnMap([
47
                ['actions', ['edit' => [], 'delete' => [], 'list' => []]],
48
                ['routing_name_pattern', '{admin}.{action}'],
49
            ])
50
        ;
51
    
52
        $admin = $this->getMockWithoutConstructor(AdminInterface::class);
53
        $admin
54
            ->expects($this->once())
55
            ->method('getConfiguration')
56
            ->willReturn($adminConfiguration)
57
        ;
58
        $admin
59
            ->expects($this->atLeastOnce())
60
            ->method('getName')
61
            ->willReturn('my_little_admin')
62
        ;
63
    
64
        $form = $this->getMockWithoutConstructor(FormInterface::class);
65
        $form
66
            ->expects($this->atLeastOnce())
67
            ->method('isValid')
68
            ->willReturn(true)
69
        ;
70
        $form
71
            ->expects($this->atLeastOnce())
72
            ->method('isSubmitted')
73
            ->willReturn(true)
74
        ;
75
    
76
        $twig = $this->getMockWithoutConstructor(Twig_Environment::class);
77
    
78
        $responder = new DeleteResponder($routing, $twig);
79
    
80
        $response = $responder->respond(
81
            $configuration,
82
            $admin,
83
            $form
84
        );
85
    
86
        $this->assertInstanceOf(RedirectResponse::class, $response);
87
    }
88
    
89
    public function testRespondWithoutSubmittedForm()
90
    {
91
        $routing = $this->getMockWithoutConstructor(RouterInterface::class);
92
        
93
        $configuration = $this->getMockWithoutConstructor(ActionConfiguration::class);
94
        $configuration
95
            ->expects($this->atLeastOnce())
96
            ->method('getParameter')
97
            ->willReturnMap([
98
                ['template', 'my_template.twig'],
99
            ])
100
        ;
101
        
102
        $admin = $this->getMockWithoutConstructor(AdminInterface::class);
103
        
104
        $form = $this->getMockWithoutConstructor(FormInterface::class);
105
        $form
106
            ->expects($this->atLeastOnce())
107
            ->method('isSubmitted')
108
            ->willReturn(false)
109
        ;
110
        
111
        $twig = $this->getMockWithoutConstructor(Twig_Environment::class);
112
        $twig
113
            ->expects($this->atLeastOnce())
114
            ->method('render')
115
            ->with('my_template.twig')
116
            ->willReturn('content')
117
        ;
118
        
119
        $responder = new DeleteResponder($routing, $twig);
120
        
121
        $response = $responder->respond(
122
            $configuration,
123
            $admin,
124
            $form
125
        );
126
        
127
        $this->assertInstanceOf(Response::class, $response);
128
    }
129
}
130