Completed
Push — master ( 4c7b9c...e919dc )
by Kamil
21:11
created

AuthenticationFailureHandlerSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 4 1
A it_extends_default_authentication_failure_handler() 0 4 1
A it_is_a_authentication_failure_handler() 0 4 1
A it_returns_json_response_if_it_was_ajax_call() 0 9 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\UserBundle\Authentication;
13
14
use PhpSpec\ObjectBehavior;
15
use Sylius\Bundle\UserBundle\Authentication\AuthenticationFailureHandler;
16
use Symfony\Component\HttpFoundation\JsonResponse;
17
use Symfony\Component\HttpFoundation\RedirectResponse;
18
use Symfony\Component\HttpFoundation\Request;
19
use Symfony\Component\HttpKernel\HttpKernelInterface;
20
use Symfony\Component\Security\Core\Exception\AuthenticationException;
21
use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface;
22
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationFailureHandler;
23
use Symfony\Component\Security\Http\HttpUtils;
24
25
/**
26
 * @mixin AuthenticationFailureHandler
27
 *
28
 * @author Arkadiusz Krakowiak <[email protected]>
29
 */
30
class AuthenticationFailureHandlerSpec extends ObjectBehavior
31
{
32
    function let(HttpKernelInterface $httpKernel, HttpUtils $httpUtils)
33
    {
34
        $this->beConstructedWith($httpKernel, $httpUtils);
35
    }
36
37
    function it_is_initializable()
38
    {
39
        $this->shouldHaveType('Sylius\Bundle\UserBundle\Authentication\AuthenticationFailureHandler');
40
    }
41
42
    function it_extends_default_authentication_failure_handler()
43
    {
44
        $this->shouldHaveType(DefaultAuthenticationFailureHandler::class);
45
    }
46
47
    function it_is_a_authentication_failure_handler()
48
    {
49
        $this->shouldImplement(AuthenticationFailureHandlerInterface::class);
50
    }
51
52
    function it_returns_json_response_if_it_was_ajax_call(
53
        Request $request,
54
        AuthenticationException $authenticationException
55
    ) {
56
        $request->isXmlHttpRequest()->willReturn(true);
57
        $authenticationException->getMessageKey()->willReturn('Invalid credentials.');
58
59
        $this->onAuthenticationFailure($request, $authenticationException)->shouldHaveType(JsonResponse::class);
60
    }
61
}
62