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

ListActionTest::testInvoke()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 79

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 79
rs 8.4581
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace LAG\AdminBundle\Tests\AdminBundle\Action;
4
5
use LAG\AdminBundle\Action\Configuration\ActionConfiguration;
6
use LAG\AdminBundle\Controller\ListAction;
7
use LAG\AdminBundle\Action\Responder\ListResponder;
8
use LAG\AdminBundle\Admin\AdminInterface;
9
use LAG\AdminBundle\Filter\Factory\FilterFormBuilder;
10
use LAG\AdminBundle\Tests\AdminTestBase;
11
use LAG\AdminBundle\Tests\Entity\TestSimpleEntity;
12
use Symfony\Component\Form\FormFactoryInterface;
13
use Symfony\Component\Form\FormInterface;
14
use Symfony\Component\HttpFoundation\Request;
15
16
class ListActionTest extends AdminTestBase
17
{
18
    public function testInvoke()
19
    {
20
        $request = new Request();
21
        $entity = new TestSimpleEntity();
22
        
23
        $actionConfiguration = $this->getMockWithoutConstructor(ActionConfiguration::class);
24
        $actionConfiguration
25
            ->method('getParameter')
26
            ->willReturnMap([
27
                ['form', 'MyForm'],
28
                ['form_options', [
29
                    'required' => false,
30
                ]],
31
            ])
32
        ;
33
        
34
        $admin = $this->getMockWithoutConstructor(AdminInterface::class);
35
        $admin
36
            ->expects($this->once())
37
            ->method('handleRequest')
38
            ->with($request)
39
        ;
40
        $admin
41
            ->expects($this->once())
42
            ->method('getEntities')
43
            ->willReturn([
44
                $entity,
45
            ])
46
        ;
47
    
48
        $form = $this->getMockWithoutConstructor(FormInterface::class);
49
        $form
50
            ->expects($this->once())
51
            ->method('handleRequest')
52
            ->with($request)
53
        ;
54
        
55
        $filterForm = $this->getMockWithoutConstructor(FormInterface::class);
56
        $filterForm
57
            ->expects($this->once())
58
            ->method('handleRequest')
59
        ;
60
        
61
        $formFactory = $this->getMockWithoutConstructor(FormFactoryInterface::class);
62
        $formFactory
63
            ->expects($this->once())
64
            ->method('create')
65
            ->with('MyForm', [
66
                $entity,
67
            ], [
68
                'required' => false,
69
            ])
70
            ->willReturn($form)
71
        ;
72
    
73
        $responder = $this->getMockWithoutConstructor(ListResponder::class);
74
        $responder
75
            ->method('respond')
76
            ->with($actionConfiguration, $admin, $form, $filterForm)
77
        ;
78
    
79
        $builder = $this->getMockWithoutConstructor(FilterFormBuilder::class);
80
        $builder
81
            ->method('build')
82
            ->with($actionConfiguration)
83
            ->willReturn($filterForm)
84
        ;
85
        
86
        $action = new ListAction(
87
            'list',
88
            $formFactory,
89
            $responder,
90
            $builder
91
        );
92
        $action->setConfiguration($actionConfiguration);
93
        $action->setAdmin($admin);
94
        
95
        $action->__invoke($request);
96
    }
97
}
98