Completed
Pull Request — master (#25)
by Jérémy
05:47
created

RefreshTokenSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 8 1
A it_is_initializable() 0 4 1
A it_refresh_token() 0 10 1
A it_refresh_token_with_ttl_update() 0 15 1
A it_throws_an_authentication_exception() 0 9 1
1
<?php
2
3
namespace spec\Gesdinet\JWTRefreshTokenBundle\Service;
4
5
use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenInterface;
6
use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenManagerInterface;
7
use Gesdinet\JWTRefreshTokenBundle\Security\Authenticator\RefreshTokenAuthenticator;
8
use Gesdinet\JWTRefreshTokenBundle\Security\Provider\RefreshTokenProvider;
9
use Lexik\Bundle\JWTAuthenticationBundle\Security\Http\Authentication\AuthenticationFailureHandler;
10
use Lexik\Bundle\JWTAuthenticationBundle\Security\Http\Authentication\AuthenticationSuccessHandler;
11
use PhpSpec\ObjectBehavior;
12
use Prophecy\Argument;
13
use Symfony\Component\HttpFoundation\Request;
14
use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken;
15
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
16
use Symfony\Component\Security\Core\User\UserProviderInterface;
17
18
class RefreshTokenSpec extends ObjectBehavior
19
{
20
    public function let(RefreshTokenAuthenticator $authenticator, RefreshTokenProvider $provider, AuthenticationSuccessHandler $successHandler, AuthenticationFailureHandler $failureHandler, RefreshTokenManagerInterface $refreshTokenManager, TokenInterface $token, UserProviderInterface $userProvider, $ttl, $providerKey, $ttlUpdate)
0 ignored issues
show
Unused Code introduced by
The parameter $token 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 $userProvider 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 $ttl 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 $providerKey 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 $ttlUpdate 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...
21
    {
22
        $ttl = 2592000;
23
        $ttlUpdate = false;
24
        $providerKey = 'testkey';
25
26
        $this->beConstructedWith($authenticator, $provider, $successHandler, $failureHandler, $refreshTokenManager, $ttl, $providerKey, $ttlUpdate);
27
    }
28
29
    public function it_is_initializable()
30
    {
31
        $this->shouldHaveType('Gesdinet\JWTRefreshTokenBundle\Service\RefreshToken');
32
    }
33
34
    public function it_refresh_token(Request $request, $refreshTokenManager, $authenticator, $token, PreAuthenticatedToken $preAuthenticatedToken, RefreshTokenInterface $refreshToken)
35
    {
36
        $authenticator->createToken(Argument::any(), Argument::any())->willReturn($token);
37
        $authenticator->authenticateToken(Argument::any(), Argument::any(), Argument::any())->willReturn($preAuthenticatedToken);
38
39
        $refreshTokenManager->get(Argument::any())->willReturn($refreshToken);
40
        $refreshToken->isValid()->willReturn(true);
41
42
        $this->refresh($request);
43
    }
44
45
    public function it_refresh_token_with_ttl_update(RefreshTokenProvider $provider, AuthenticationSuccessHandler $successHandler, AuthenticationFailureHandler $failureHandler, Request $request, $refreshTokenManager, $authenticator, $token, PreAuthenticatedToken $preAuthenticatedToken, RefreshTokenInterface $refreshToken)
46
    {
47
        $this->beConstructedWith($authenticator, $provider, $successHandler, $failureHandler, $refreshTokenManager, 2592000, 'testkey', true);
48
49
        $authenticator->createToken(Argument::any(), Argument::any())->willReturn($token);
50
        $authenticator->authenticateToken(Argument::any(), Argument::any(), Argument::any())->willReturn($preAuthenticatedToken);
51
52
        $refreshTokenManager->get(Argument::any())->willReturn($refreshToken);
53
        $refreshToken->isValid()->willReturn(true);
54
55
        $refreshToken->getValid()->willReturn(new \DateTime());
56
        $refreshTokenManager->save($refreshToken)->shouldBeCalled();
57
58
        $this->refresh($request);
59
    }
60
61
    public function it_throws_an_authentication_exception(Request $request, $refreshTokenManager, $authenticator, $token, PreAuthenticatedToken $preAuthenticatedToken, RefreshTokenInterface $refreshToken, $failureHandler)
0 ignored issues
show
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...
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...
62
    {
63
        $authenticator->createToken(Argument::any(), Argument::any())->willReturn($token);
64
        $authenticator->authenticateToken(Argument::any(), Argument::any(), Argument::any())->willReturn($preAuthenticatedToken);
65
66
        $failureHandler->onAuthenticationFailure(Argument::any(), Argument::any())->shouldBeCalled();
67
68
        $this->refresh($request);
69
    }
70
}
71