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

it_refresh_token_with_ttl_update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 15
rs 9.4286
cc 1
eloc 9
nc 1
nop 9

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
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