Completed
Push — scalar-types/ui ( 162de3 )
by Kamil
22:15
created

SecurityControllerSpec::it_renders_login_form()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 33
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 25
nc 1
nop 8

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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\UiBundle\Controller;
15
16
use PhpSpec\ObjectBehavior;
17
use Sylius\Bundle\UiBundle\Controller\SecurityController;
18
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
19
use Symfony\Component\Form\Form;
20
use Symfony\Component\Form\FormFactoryInterface;
21
use Symfony\Component\Form\FormView;
22
use Symfony\Component\HttpFoundation\ParameterBag;
23
use Symfony\Component\HttpFoundation\Request;
24
use Symfony\Component\HttpFoundation\Response;
25
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
26
27
/**
28
 * @author Paweł Jędrzejewski <[email protected]>
29
 */
30
final class SecurityControllerSpec extends ObjectBehavior
31
{
32
    function let(AuthenticationUtils $authenticationUtils, FormFactoryInterface $formFactory, EngineInterface $templatingEngine): void
33
    {
34
        $this->beConstructedWith($authenticationUtils, $formFactory, $templatingEngine);
35
    }
36
37
    function it_renders_login_form(
38
        Request $request,
39
        ParameterBag $requestAttributes,
40
        AuthenticationUtils $authenticationUtils,
41
        FormFactoryInterface $formFactory,
42
        Form $form,
43
        FormView $formView,
44
        EngineInterface $templatingEngine,
45
        Response $response
46
    ): void {
47
        $authenticationUtils->getLastAuthenticationError()->willReturn('Bad credentials.');
48
        $authenticationUtils->getLastUsername()->willReturn('john.doe');
49
50
        $request->attributes = $requestAttributes;
51
        $requestAttributes->get('_sylius')->willReturn([
52
            'template' => 'CustomTemplateName',
53
            'form' => 'custom_form_type',
54
        ]);
55
56
        $formFactory->createNamed('', 'custom_form_type')->willReturn($form);
57
        $form->createView()->willReturn($formView);
58
59
        $templatingEngine
60
            ->renderResponse('CustomTemplateName', [
61
                'form' => $formView,
62
                'last_username' => 'john.doe',
63
                'last_error' => 'Bad credentials.',
64
            ])
65
            ->willReturn($response)
66
        ;
67
68
        $this->loginAction($request)->shouldReturn($response);
69
    }
70
71
    function it_throws_an_exception_when_check_action_is_accessed(Request $request): void
72
    {
73
        $this
74
            ->shouldThrow(new \RuntimeException('You must configure the check path to be handled by the firewall.'))
75
            ->during('checkAction', [$request]);
76
    }
77
78
    function it_throws_an_exception_when_logout_action_is_accessed(Request $request): void
79
    {
80
        $this
81
            ->shouldThrow(new \RuntimeException('You must configure the logout path to be handled by the firewall.'))
82
            ->during('logoutAction', [$request]);
83
    }
84
}
85