|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace ShlinkioTest\Shlink\CLI\Command\Api; |
|
5
|
|
|
|
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
|
7
|
|
|
use Prophecy\Argument; |
|
8
|
|
|
use Prophecy\Prophecy\ObjectProphecy; |
|
9
|
|
|
use Shlinkio\Shlink\CLI\Command\Api\GenerateKeyCommand; |
|
10
|
|
|
use Shlinkio\Shlink\Rest\Entity\ApiKey; |
|
11
|
|
|
use Shlinkio\Shlink\Rest\Service\ApiKeyService; |
|
12
|
|
|
use Symfony\Component\Console\Application; |
|
13
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
|
14
|
|
|
use Zend\I18n\Translator\Translator; |
|
15
|
|
|
|
|
16
|
|
|
class GenerateKeyCommandTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var CommandTester |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $commandTester; |
|
22
|
|
|
/** |
|
23
|
|
|
* @var ObjectProphecy |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $apiKeyService; |
|
26
|
|
|
|
|
27
|
|
|
public function setUp() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->apiKeyService = $this->prophesize(ApiKeyService::class); |
|
30
|
|
|
$command = new GenerateKeyCommand($this->apiKeyService->reveal(), Translator::factory([])); |
|
31
|
|
|
$app = new Application(); |
|
32
|
|
|
$app->add($command); |
|
33
|
|
|
$this->commandTester = new CommandTester($command); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @test |
|
38
|
|
|
*/ |
|
39
|
|
View Code Duplication |
public function noExpirationDateIsDefinedIfNotProvided() |
|
|
|
|
|
|
40
|
|
|
{ |
|
41
|
|
|
$this->apiKeyService->create(null)->shouldBeCalledTimes(1) |
|
42
|
|
|
->willReturn(new ApiKey()); |
|
43
|
|
|
$this->commandTester->execute([ |
|
44
|
|
|
'command' => 'api-key:generate', |
|
45
|
|
|
]); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @test |
|
50
|
|
|
*/ |
|
51
|
|
View Code Duplication |
public function expirationDateIsDefinedIfProvided() |
|
|
|
|
|
|
52
|
|
|
{ |
|
53
|
|
|
$this->apiKeyService->create(Argument::type(\DateTime::class))->shouldBeCalledTimes(1) |
|
54
|
|
|
->willReturn(new ApiKey()); |
|
55
|
|
|
$this->commandTester->execute([ |
|
56
|
|
|
'command' => 'api-key:generate', |
|
57
|
|
|
'--expirationDate' => '2016-01-01', |
|
58
|
|
|
]); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.