|
1
|
|
|
<?php |
|
2
|
|
|
namespace ShlinkioTest\Shlink\CLI\Command\Tag; |
|
3
|
|
|
|
|
4
|
|
|
use PHPUnit\Framework\TestCase; |
|
5
|
|
|
use Prophecy\Prophecy\MethodProphecy; |
|
6
|
|
|
use Prophecy\Prophecy\ObjectProphecy; |
|
7
|
|
|
use Shlinkio\Shlink\CLI\Command\Tag\CreateTagCommand; |
|
8
|
|
|
use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface; |
|
9
|
|
|
use Symfony\Component\Console\Application; |
|
10
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
|
11
|
|
|
use Zend\I18n\Translator\Translator; |
|
12
|
|
|
|
|
13
|
|
View Code Duplication |
class CreateTagCommandTest extends TestCase |
|
|
|
|
|
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var CreateTagCommand |
|
17
|
|
|
*/ |
|
18
|
|
|
private $command; |
|
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var CommandTester |
|
21
|
|
|
*/ |
|
22
|
|
|
private $commandTester; |
|
23
|
|
|
/** |
|
24
|
|
|
* @var ObjectProphecy |
|
25
|
|
|
*/ |
|
26
|
|
|
private $tagService; |
|
27
|
|
|
|
|
28
|
|
|
public function setUp() |
|
29
|
|
|
{ |
|
30
|
|
|
$this->tagService = $this->prophesize(TagServiceInterface::class); |
|
31
|
|
|
|
|
32
|
|
|
$command = new CreateTagCommand($this->tagService->reveal(), Translator::factory([])); |
|
33
|
|
|
$app = new Application(); |
|
34
|
|
|
$app->add($command); |
|
35
|
|
|
|
|
36
|
|
|
$this->commandTester = new CommandTester($command); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @test |
|
41
|
|
|
*/ |
|
42
|
|
|
public function errorIsReturnedWhenNoTagsAreProvided() |
|
43
|
|
|
{ |
|
44
|
|
|
$this->commandTester->execute([]); |
|
45
|
|
|
|
|
46
|
|
|
$output = $this->commandTester->getDisplay(); |
|
47
|
|
|
$this->assertContains('You have to provide at least one tag name', $output); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @test |
|
52
|
|
|
*/ |
|
53
|
|
|
public function serviceIsInvokedOnSuccess() |
|
54
|
|
|
{ |
|
55
|
|
|
$tagNames = ['foo', 'bar']; |
|
56
|
|
|
/** @var MethodProphecy $createTags */ |
|
57
|
|
|
$createTags = $this->tagService->createTags($tagNames)->willReturn([]); |
|
58
|
|
|
|
|
59
|
|
|
$this->commandTester->execute([ |
|
60
|
|
|
'--name' => $tagNames, |
|
61
|
|
|
]); |
|
62
|
|
|
$output = $this->commandTester->getDisplay(); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertContains(sprintf('Created tags: ["%s"]', implode('", "', $tagNames)), $output); |
|
65
|
|
|
$createTags->shouldHaveBeenCalled(); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
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.