Completed
Pull Request — master (#77)
by Evgeny
11:21 queued 06:43
created

RevokeRefreshTokenCommandSpec::let()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace spec\Gesdinet\JWTRefreshTokenBundle\Command;
4
5
use Gesdinet\JWTRefreshTokenBundle\Command\RevokeRefreshTokenCommand;
6
use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenInterface;
7
use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenManagerInterface;
8
use PhpSpec\ObjectBehavior;
9
use Prophecy\Argument;
10
use Symfony\Component\Console\Command\Command;
11
use Symfony\Component\Console\Input\InputDefinition;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Output\OutputInterface;
14
15
class RevokeRefreshTokenCommandSpec extends ObjectBehavior
16
{
17
    public function let(RefreshTokenManagerInterface $refreshTokenManager)
18
    {
19
        $this->beConstructedWith($refreshTokenManager);
20
    }
21
22
    public function it_is_initializable()
23
    {
24
        $this->shouldHaveType(RevokeRefreshTokenCommand::class);
25
    }
26
27
    public function it_is_a_command()
28
    {
29
        $this->shouldHaveType(Command::class);
30
    }
31
32
    public function it_has_a_name()
33
    {
34
        $this->getName()->shouldReturn('gesdinet:jwt:revoke');
35
    }
36
37
    public function it_revokes_a_refresh_token(InputInterface $input, OutputInterface $output, RefreshTokenManagerInterface $refreshTokenManager, RefreshTokenInterface $refreshToken)
38
    {
39
        $input->bind(Argument::type(InputDefinition::class))->shouldBeCalled();
40
        $input->isInteractive()->willReturn(false);
41
        $input->hasArgument(Argument::exact('command'))->willReturn(false);
42
        $input->validate()->shouldBeCalled();
43
44
        $argument = Argument::type('string');
45
        $input->getArgument(Argument::exact('refresh_token'))->willReturn($argument);
46
        $refreshTokenManager->get($argument)->shouldBeCalled()->willReturn($refreshToken);
47
48
        $refreshTokenManager->delete($refreshToken)->shouldBeCalled();
49
        $output->writeln(Argument::any())->shouldBeCalled();
50
51
        $this->run($input, $output);
52
    }
53
54
    public function it_not_revokes_a_refresh_token(InputInterface $input, OutputInterface $output, RefreshTokenManagerInterface $refreshTokenManager)
55
    {
56
        $input->bind(Argument::type(InputDefinition::class))->shouldBeCalled();
57
        $input->isInteractive()->willReturn(false);
58
        $input->hasArgument(Argument::exact('command'))->willReturn(false);
59
        $input->validate()->shouldBeCalled();
60
61
        $argument = Argument::type('string');
62
        $input->getArgument(Argument::exact('refresh_token'))->willReturn($argument);
63
        $refreshTokenManager->get($argument)->willReturn(null);
64
65
        $this->run($input, $output)->shouldBe(-1);
66
    }
67
}
68