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