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

DeleteActionTest::testInvoke()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 58

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 58
rs 8.9163
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\DeleteAction;
7
use LAG\AdminBundle\Action\Responder\DeleteResponder;
8
use LAG\AdminBundle\Admin\AdminInterface;
9
use LAG\AdminBundle\Tests\AdminTestBase;
10
use LAG\AdminBundle\Tests\Entity\TestSimpleEntity;
11
use Symfony\Component\Form\FormFactoryInterface;
12
use Symfony\Component\Form\FormInterface;
13
use Symfony\Component\HttpFoundation\Request;
14
15
class DeleteActionTest extends AdminTestBase
16
{
17
    public function testInvoke()
18
    {
19
        $entity = new TestSimpleEntity();
20
        $request = new Request([], [], []);
21
        
22
        $actionConfiguration = $this->getMockWithoutConstructor(ActionConfiguration::class);
23
        $actionConfiguration
24
            ->method('getParameter')
25
            ->willReturnMap([
26
                ['form', 'MyForm'],
27
                ['form_options', [
28
                    'key' => 'value',
29
                ]],
30
            ])
31
        ;
32
    
33
        $admin = $this->getMockWithoutConstructor(AdminInterface::class);
34
        $admin
35
            ->expects($this->once())
36
            ->method('remove')
37
            ->willReturn($entity)
38
        ;
39
        
40
        $form = $this->getMockWithoutConstructor(FormInterface::class);
41
        $form
42
            ->method('isValid')
43
            ->willReturn(true)
44
        ;
45
        $form
46
            ->method('isSubmitted')
47
            ->willReturn(true)
48
        ;
49
        
50
        $formFactory = $this->getMockWithoutConstructor(FormFactoryInterface::class);
51
        $formFactory
52
            ->expects($this->once())
53
            ->method('create')
54
            ->with('MyForm', null, [
55
                'key' => 'value',
56
            ])
57
            ->willReturn($form)
58
        ;
59
60
        $responder = $this->getMockWithoutConstructor(DeleteResponder::class);
61
        $responder
62
            ->method('respond')
63
            ->with($actionConfiguration, $admin, $form)
64
        ;
65
        $action = new DeleteAction(
66
            'delete',
67
            $formFactory,
68
            $responder
69
        );
70
        $action->setConfiguration($actionConfiguration);
71
        $action->setAdmin($admin);
72
        
73
        $action->__invoke($request);
74
    }
75
}
76