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

EditActionTest::testInvoke()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 55

Duplication

Lines 0
Ratio 0 %

Importance

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