Completed
Push — master ( 9ab4b9...065cdd )
by Alejandro
09:44
created

errorIsReturnedIfServiceThrowsException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 13
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 0
dl 13
loc 13
rs 9.4285
1
<?php
2
namespace ShlinkioTest\Shlink\CLI\Command\Api;
3
4
use PHPUnit_Framework_TestCase as TestCase;
5
use Prophecy\Prophecy\ObjectProphecy;
6
use Shlinkio\Shlink\CLI\Command\Api\DisableKeyCommand;
7
use Shlinkio\Shlink\Common\Exception\InvalidArgumentException;
8
use Shlinkio\Shlink\Rest\Service\ApiKeyService;
9
use Symfony\Component\Console\Application;
10
use Symfony\Component\Console\Tester\CommandTester;
11
use Zend\I18n\Translator\Translator;
12
13
class DisableKeyCommandTest extends TestCase
14
{
15
    /**
16
     * @var CommandTester
17
     */
18
    protected $commandTester;
19
    /**
20
     * @var ObjectProphecy
21
     */
22
    protected $apiKeyService;
23
24 View Code Duplication
    public function setUp()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
25
    {
26
        $this->apiKeyService = $this->prophesize(ApiKeyService::class);
27
        $command = new DisableKeyCommand($this->apiKeyService->reveal(), Translator::factory([]));
28
        $app = new Application();
29
        $app->add($command);
30
        $this->commandTester = new CommandTester($command);
31
    }
32
33
    /**
34
     * @test
35
     */
36
    public function providedApiKeyIsDisabled()
37
    {
38
        $apiKey = 'abcd1234';
39
        $this->apiKeyService->disable($apiKey)->shouldBeCalledTimes(1);
40
        $this->commandTester->execute([
41
            'command' => 'api-key:disable',
42
            'apiKey' => $apiKey,
43
        ]);
44
    }
45
46
    /**
47
     * @test
48
     */
49 View Code Duplication
    public function errorIsReturnedIfServiceThrowsException()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
50
    {
51
        $apiKey = 'abcd1234';
52
        $this->apiKeyService->disable($apiKey)->willThrow(InvalidArgumentException::class)
53
                                              ->shouldBeCalledTimes(1);
54
55
        $this->commandTester->execute([
56
            'command' => 'api-key:disable',
57
            'apiKey' => $apiKey,
58
        ]);
59
        $output = $this->commandTester->getDisplay();
60
        $this->assertEquals('API key "abcd1234" does not exist.' . PHP_EOL, $output);
61
    }
62
}
63