|
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\RenameTagCommand; |
|
8
|
|
|
use Shlinkio\Shlink\Core\Entity\Tag; |
|
9
|
|
|
use Shlinkio\Shlink\Core\Exception\EntityDoesNotExistException; |
|
10
|
|
|
use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface; |
|
11
|
|
|
use Symfony\Component\Console\Application; |
|
12
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
|
13
|
|
|
use Zend\I18n\Translator\Translator; |
|
14
|
|
|
|
|
15
|
|
|
class RenameTagCommandTest extends TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var RenameTagCommand |
|
19
|
|
|
*/ |
|
20
|
|
|
private $command; |
|
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var CommandTester |
|
23
|
|
|
*/ |
|
24
|
|
|
private $commandTester; |
|
25
|
|
|
/** |
|
26
|
|
|
* @var ObjectProphecy |
|
27
|
|
|
*/ |
|
28
|
|
|
private $tagService; |
|
29
|
|
|
|
|
30
|
|
|
public function setUp() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->tagService = $this->prophesize(TagServiceInterface::class); |
|
33
|
|
|
|
|
34
|
|
|
$command = new RenameTagCommand($this->tagService->reveal(), Translator::factory([])); |
|
35
|
|
|
$app = new Application(); |
|
36
|
|
|
$app->add($command); |
|
37
|
|
|
|
|
38
|
|
|
$this->commandTester = new CommandTester($command); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @test |
|
43
|
|
|
*/ |
|
44
|
|
View Code Duplication |
public function errorIsPrintedIfExceptionIsThrown() |
|
|
|
|
|
|
45
|
|
|
{ |
|
46
|
|
|
$oldName = 'foo'; |
|
47
|
|
|
$newName = 'bar'; |
|
48
|
|
|
/** @var MethodProphecy $renameTag */ |
|
49
|
|
|
$renameTag = $this->tagService->renameTag($oldName, $newName)->willThrow(EntityDoesNotExistException::class); |
|
50
|
|
|
|
|
51
|
|
|
$this->commandTester->execute([ |
|
52
|
|
|
'oldName' => $oldName, |
|
53
|
|
|
'newName' => $newName, |
|
54
|
|
|
]); |
|
55
|
|
|
$output = $this->commandTester->getDisplay(); |
|
56
|
|
|
|
|
57
|
|
|
$this->assertContains('A tag with name "foo" was not found', $output); |
|
58
|
|
|
$renameTag->shouldHaveBeenCalled(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @test |
|
63
|
|
|
*/ |
|
64
|
|
View Code Duplication |
public function successIsPrintedIfNoErrorOccurs() |
|
|
|
|
|
|
65
|
|
|
{ |
|
66
|
|
|
$oldName = 'foo'; |
|
67
|
|
|
$newName = 'bar'; |
|
68
|
|
|
/** @var MethodProphecy $renameTag */ |
|
69
|
|
|
$renameTag = $this->tagService->renameTag($oldName, $newName)->willReturn(new Tag()); |
|
70
|
|
|
|
|
71
|
|
|
$this->commandTester->execute([ |
|
72
|
|
|
'oldName' => $oldName, |
|
73
|
|
|
'newName' => $newName, |
|
74
|
|
|
]); |
|
75
|
|
|
$output = $this->commandTester->getDisplay(); |
|
76
|
|
|
|
|
77
|
|
|
$this->assertContains('Tag properly renamed', $output); |
|
78
|
|
|
$renameTag->shouldHaveBeenCalled(); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.