|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace ShlinkioTest\Shlink\CLI\Command\Api; |
|
5
|
|
|
|
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
|
7
|
|
|
use Prophecy\Prophecy\ObjectProphecy; |
|
8
|
|
|
use Shlinkio\Shlink\CLI\Command\Api\ListKeysCommand; |
|
9
|
|
|
use Shlinkio\Shlink\Rest\Entity\ApiKey; |
|
10
|
|
|
use Shlinkio\Shlink\Rest\Service\ApiKeyService; |
|
11
|
|
|
use Symfony\Component\Console\Application; |
|
12
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
|
13
|
|
|
use Zend\I18n\Translator\Translator; |
|
14
|
|
|
|
|
15
|
|
|
class ListKeysCommandTest extends TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var CommandTester |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $commandTester; |
|
21
|
|
|
/** |
|
22
|
|
|
* @var ObjectProphecy |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $apiKeyService; |
|
25
|
|
|
|
|
26
|
|
|
public function setUp() |
|
27
|
|
|
{ |
|
28
|
|
|
$this->apiKeyService = $this->prophesize(ApiKeyService::class); |
|
29
|
|
|
$command = new ListKeysCommand($this->apiKeyService->reveal(), Translator::factory([])); |
|
30
|
|
|
$app = new Application(); |
|
31
|
|
|
$app->add($command); |
|
32
|
|
|
$this->commandTester = new CommandTester($command); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @test |
|
37
|
|
|
*/ |
|
38
|
|
|
public function everythingIsListedIfEnabledOnlyIsNotProvided() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->apiKeyService->listKeys(false)->willReturn([ |
|
41
|
|
|
new ApiKey(), |
|
42
|
|
|
new ApiKey(), |
|
43
|
|
|
new ApiKey(), |
|
44
|
|
|
])->shouldBeCalledOnce(); |
|
45
|
|
|
|
|
46
|
|
|
$this->commandTester->execute([ |
|
47
|
|
|
'command' => ListKeysCommand::NAME, |
|
48
|
|
|
]); |
|
49
|
|
|
$output = $this->commandTester->getDisplay(); |
|
50
|
|
|
|
|
51
|
|
|
$this->assertContains('Key', $output); |
|
52
|
|
|
$this->assertContains('Is enabled', $output); |
|
53
|
|
|
$this->assertContains(' +++ ', $output); |
|
54
|
|
|
$this->assertNotContains(' --- ', $output); |
|
55
|
|
|
$this->assertContains('Expiration date', $output); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @test |
|
60
|
|
|
*/ |
|
61
|
|
|
public function onlyEnabledKeysAreListedIfEnabledOnlyIsProvided() |
|
62
|
|
|
{ |
|
63
|
|
|
$this->apiKeyService->listKeys(true)->willReturn([ |
|
64
|
|
|
(new ApiKey())->disable(), |
|
65
|
|
|
new ApiKey(), |
|
66
|
|
|
])->shouldBeCalledOnce(); |
|
67
|
|
|
|
|
68
|
|
|
$this->commandTester->execute([ |
|
69
|
|
|
'command' => ListKeysCommand::NAME, |
|
70
|
|
|
'--enabledOnly' => true, |
|
71
|
|
|
]); |
|
72
|
|
|
$output = $this->commandTester->getDisplay(); |
|
73
|
|
|
|
|
74
|
|
|
$this->assertContains('Key', $output); |
|
75
|
|
|
$this->assertNotContains('Is enabled', $output); |
|
76
|
|
|
$this->assertNotContains(' +++ ', $output); |
|
77
|
|
|
$this->assertNotContains(' --- ', $output); |
|
78
|
|
|
$this->assertContains('Expiration date', $output); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|