Completed
Push — master ( 12ace7...d998d0 )
by Kamil
35:58
created

SecurityControllerSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 8

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 0
cbo 8
dl 0
loc 58
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 4 1
B it_renders_login_form() 0 31 1
A it_throws_an_exception_when_check_action_is_accessed() 0 6 1
A it_throws_an_exception_when_logout_action_is_accessed() 0 6 1
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
namespace spec\Sylius\Bundle\UiBundle\Controller;
13
14
use PhpSpec\ObjectBehavior;
15
use Prophecy\Argument;
16
use Sylius\Bundle\UiBundle\Controller\SecurityController;
17
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
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
 * @mixin SecurityController
29
 *
30
 * @author Paweł Jędrzejewski <[email protected]>
31
 */
32
class SecurityControllerSpec extends ObjectBehavior
33
{
34
    function let(AuthenticationUtils $authenticationUtils, FormFactoryInterface $formFactory, EngineInterface $templatingEngine)
35
    {
36
        $this->beConstructedWith($authenticationUtils, $formFactory, $templatingEngine);
37
    }
38
39
    function it_is_initializable()
40
    {
41
        $this->shouldHaveType('Sylius\Bundle\UiBundle\Controller\SecurityController');
42
    }
43
44
    function it_renders_login_form(
45
        Request $request,
46
        ParameterBag $requestAttributes,
47
        AuthenticationUtils $authenticationUtils,
48
        FormFactoryInterface $formFactory,
49
        Form $form,
50
        FormView $formView,
51
        EngineInterface $templatingEngine,
52
        Response $response
53
    ) {
54
        $authenticationUtils->getLastAuthenticationError()->willReturn('Bad credentials.');
55
        $authenticationUtils->getLastUsername()->willReturn('john.doe');
56
        
57
        $request->attributes = $requestAttributes;
58
        $requestAttributes->get('_sylius[template]', 'SyliusUiBundle:Security:login.html.twig', true)->willReturn('CustomTemplateName');
59
        $requestAttributes->get('_sylius[form]', 'sylius_security_login', true)->willReturn('custom_form_type');
60
        
61
        $formFactory->createNamed('', 'custom_form_type')->willReturn($form);
62
        $form->createView()->willReturn($formView);
63
64
        $templatingEngine
65
            ->renderResponse('CustomTemplateName', array(
66
                'form' => $formView,
67
                'last_username' => 'john.doe',
68
                'last_error' => 'Bad credentials.',
69
            ))
70
            ->willReturn($response)
71
        ;
72
        
73
        $this->loginAction($request)->shouldReturn($response);
74
    }
75
76
    function it_throws_an_exception_when_check_action_is_accessed(Request $request)
77
    {
78
        $this
79
            ->shouldThrow(new \RuntimeException('You must configure the check path to be handled by the firewall.'))
80
            ->during('checkAction', array($request));
81
    }
82
83
    function it_throws_an_exception_when_logout_action_is_accessed(Request $request)
84
    {
85
        $this
86
            ->shouldThrow(new \RuntimeException('You must configure the logout path to be handled by the firewall.'))
87
            ->during('logoutAction', array($request));
88
    }
89
}
90