2016-08-06 19:26:07 +03:00
|
|
|
<?php
|
2017-10-12 11:13:20 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-08-06 19:26:07 +03:00
|
|
|
namespace ShlinkioTest\Shlink\CLI\Command\Api;
|
|
|
|
|
2017-03-24 22:34:18 +03:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2016-08-06 19:26:07 +03:00
|
|
|
use Prophecy\Prophecy\ObjectProphecy;
|
|
|
|
use Shlinkio\Shlink\CLI\Command\Api\DisableKeyCommand;
|
|
|
|
use Shlinkio\Shlink\Common\Exception\InvalidArgumentException;
|
|
|
|
use Shlinkio\Shlink\Rest\Service\ApiKeyService;
|
|
|
|
use Symfony\Component\Console\Application;
|
|
|
|
use Symfony\Component\Console\Tester\CommandTester;
|
|
|
|
use Zend\I18n\Translator\Translator;
|
|
|
|
|
|
|
|
class DisableKeyCommandTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var CommandTester
|
|
|
|
*/
|
|
|
|
protected $commandTester;
|
|
|
|
/**
|
|
|
|
* @var ObjectProphecy
|
|
|
|
*/
|
|
|
|
protected $apiKeyService;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
$this->apiKeyService = $this->prophesize(ApiKeyService::class);
|
|
|
|
$command = new DisableKeyCommand($this->apiKeyService->reveal(), Translator::factory([]));
|
|
|
|
$app = new Application();
|
|
|
|
$app->add($command);
|
|
|
|
$this->commandTester = new CommandTester($command);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function providedApiKeyIsDisabled()
|
|
|
|
{
|
|
|
|
$apiKey = 'abcd1234';
|
2018-11-11 15:18:21 +03:00
|
|
|
$this->apiKeyService->disable($apiKey)->shouldBeCalledOnce();
|
2016-08-06 19:26:07 +03:00
|
|
|
$this->commandTester->execute([
|
|
|
|
'command' => 'api-key:disable',
|
|
|
|
'apiKey' => $apiKey,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function errorIsReturnedIfServiceThrowsException()
|
|
|
|
{
|
|
|
|
$apiKey = 'abcd1234';
|
|
|
|
$this->apiKeyService->disable($apiKey)->willThrow(InvalidArgumentException::class)
|
2018-11-11 15:18:21 +03:00
|
|
|
->shouldBeCalledOnce();
|
2016-08-06 19:26:07 +03:00
|
|
|
|
|
|
|
$this->commandTester->execute([
|
|
|
|
'command' => 'api-key:disable',
|
|
|
|
'apiKey' => $apiKey,
|
|
|
|
]);
|
|
|
|
$output = $this->commandTester->getDisplay();
|
2017-12-27 19:36:07 +03:00
|
|
|
$this->assertContains('API key "abcd1234" does not exist.', $output);
|
2016-08-06 19:26:07 +03:00
|
|
|
}
|
|
|
|
}
|