Completed
Pull Request — master (#98)
by Alejandro
06:29
created

CreateTagCommandTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
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
0 ignored issues
show
Duplication introduced by
This class 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...
14
{
15
    /**
16
     * @var CreateTagCommand
17
     */
18
    private $command;
0 ignored issues
show
Unused Code introduced by
The property $command is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
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