AttachRefreshTokenOnSuccessListenerSpec   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 7 1
A it_is_initializable() 0 4 1
A it_attach_token_on_refresh() 0 17 1
A it_attach_token_on_credentials_auth() 0 23 1
A it_is_not_valid_user() 0 7 1
1
<?php
2
3
namespace spec\Gesdinet\JWTRefreshTokenBundle\EventListener;
4
5
use Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken;
6
use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenManagerInterface;
7
use Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationSuccessEvent;
8
use PhpSpec\ObjectBehavior;
9
use Prophecy\Argument;
10
use Symfony\Component\Security\Core\User\UserInterface;
11
use Symfony\Component\Validator\ConstraintViolationList;
12
use Symfony\Component\Validator\Validator\ValidatorInterface;
13
use Symfony\Component\HttpFoundation\RequestStack;
14
use Symfony\Component\HttpFoundation\Request;
15
use Symfony\Component\HttpFoundation\HeaderBag;
16
use Symfony\Component\HttpFoundation\ParameterBag;
17
18
class AttachRefreshTokenOnSuccessListenerSpec extends ObjectBehavior
19
{
20
    const TOKEN_PARAMETER_NAME = 'refresh_token';
21
22
    public function let(RefreshTokenManagerInterface $refreshTokenManager, ValidatorInterface $validator, RequestStack $requestStack)
23
    {
24
        $ttl = 2592000;
25
        $userIdentityField = 'username';
26
        $singleUse = false;
27
        $this->beConstructedWith($refreshTokenManager, $ttl, $validator, $requestStack, $userIdentityField, self::TOKEN_PARAMETER_NAME, $singleUse);
28
    }
29
30
    public function it_is_initializable()
31
    {
32
        $this->shouldHaveType('Gesdinet\JWTRefreshTokenBundle\EventListener\AttachRefreshTokenOnSuccessListener');
33
    }
34
35
    public function it_attach_token_on_refresh(AuthenticationSuccessEvent $event, UserInterface $user, RefreshToken $refreshToken, $refreshTokenManager, RequestStack $requestStack)
0 ignored issues
show
Unused Code introduced by
The parameter $refreshToken is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $refreshTokenManager is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
36
    {
37
        $event->getData()->willReturn(array());
38
        $event->getUser()->willReturn($user);
39
40
        $refreshTokenArray = array(self::TOKEN_PARAMETER_NAME => 'thepreviouslyissuedrefreshtoken');
41
        $headers = new HeaderBag(array('content_type' => 'not-json'));
42
        $request = new Request();
43
        $request->headers = $headers;
44
        $request->request = new ParameterBag($refreshTokenArray);
45
46
        $requestStack->getCurrentRequest()->willReturn($request);
47
48
        $event->setData(Argument::exact($refreshTokenArray))->shouldBeCalled();
49
50
        $this->attachRefreshToken($event);
51
    }
52
53
    public function it_attach_token_on_credentials_auth(HeaderBag $headers, ParameterBag $requestBag, AuthenticationSuccessEvent $event, UserInterface $user, RefreshToken $refreshToken, $refreshTokenManager, $validator, RequestStack $requestStack)
0 ignored issues
show
Unused Code introduced by
The parameter $headers is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $requestBag is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
54
    {
55
        $event->getData()->willReturn(array());
56
        $event->getUser()->willReturn($user);
57
58
        $headers = new HeaderBag(array('content_type' => 'not-json'));
59
        $request = new Request();
60
        $request->headers = $headers;
61
        $request->request = new ParameterBag();
62
63
        $requestStack->getCurrentRequest()->willReturn($request);
64
65
        $refreshTokenManager->create()->willReturn($refreshToken);
66
67
        $violationList = new ConstraintViolationList(array());
68
        $validator->validate($refreshToken)->willReturn($violationList);
69
70
        $refreshTokenManager->save($refreshToken)->shouldBeCalled();
71
72
        $event->setData(Argument::any())->shouldBeCalled();
73
74
        $this->attachRefreshToken($event);
75
    }
76
77
    public function it_is_not_valid_user(AuthenticationSuccessEvent $event)
78
    {
79
        $event->getData()->willReturn(array());
80
        $event->getUser()->willReturn(null);
81
82
        $this->attachRefreshToken($event);
83
    }
84
}
85