it_refresh_token_with_ttl_update()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 1
nc 1
nop 10

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\EventDispatcher\EventDispatcherInterface;
14
use Symfony\Component\HttpFoundation\Request;
15
use Symfony\Component\Security\Core\User\User;
16
use Symfony\Component\Security\Guard\Token\PostAuthenticationGuardToken;
17
18
class RefreshTokenSpec extends ObjectBehavior
19
{
20
    public function let(RefreshTokenAuthenticator $authenticator, RefreshTokenProvider $provider, AuthenticationSuccessHandler $successHandler, AuthenticationFailureHandler $failureHandler, RefreshTokenManagerInterface $refreshTokenManager, EventDispatcherInterface $eventDispatcher)
21
    {
22
        $ttl = 2592000;
23
        $ttlUpdate = false;
24
        $providerKey = 'testkey';
25
26
        $this->beConstructedWith($authenticator, $provider, $successHandler, $failureHandler, $refreshTokenManager, $ttl, $providerKey, $ttlUpdate, $eventDispatcher);
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, PostAuthenticationGuardToken $postAuthenticationGuardToken, RefreshTokenInterface $refreshToken)
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...
35
    {
36
        $authenticator->getCredentials(Argument::any())->willReturn(['token' => '1234']);
37
        $authenticator->getUser(Argument::any(), Argument::any())->willReturn(new User('test', 'test'));
38
        $authenticator->createAuthenticatedToken(Argument::any(), Argument::any())->willReturn($postAuthenticationGuardToken);
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, PostAuthenticationGuardToken $postAuthenticationGuardToken, RefreshTokenInterface $refreshToken, EventDispatcherInterface $eventDispatcher)
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...
46
    {
47
        $this->beConstructedWith($authenticator, $provider, $successHandler, $failureHandler, $refreshTokenManager, 2592000, 'testkey', true, $eventDispatcher);
48
49
        $authenticator->getCredentials(Argument::any())->willReturn(['token' => '1234']);
50
        $authenticator->getUser(Argument::any(), Argument::any())->willReturn(new User('test', 'test'));
51
        $authenticator->createAuthenticatedToken(Argument::any(), Argument::any())->willReturn($postAuthenticationGuardToken);
52
53
        $refreshTokenManager->get(Argument::any())->willReturn($refreshToken);
54
        $refreshToken->isValid()->willReturn(true);
55
56
        $refreshToken->setValid(Argument::any())->shouldBeCalled();
57
        $refreshTokenManager->save($refreshToken)->shouldBeCalled();
58
59
        $this->refresh($request);
60
    }
61
62
    public function it_throws_an_authentication_exception(Request $request, $authenticator, PostAuthenticationGuardToken $postAuthenticationGuardToken, $failureHandler)
63
    {
64
        $authenticator->getCredentials(Argument::any())->willReturn(['token' => '1234']);
65
        $authenticator->getUser(Argument::any(), Argument::any())->willReturn(new User('test', 'test'));
66
        $authenticator->createAuthenticatedToken(Argument::any(), Argument::any())->willReturn($postAuthenticationGuardToken);
67
68
        $failureHandler->onAuthenticationFailure(Argument::any(), Argument::any())->shouldBeCalled();
69
70
        $this->refresh($request);
71
    }
72
}
73