Completed
Push — master ( b53e51...1009f9 )
by Alejandro
04:13 queued 38s
created

existingValueIsKeptIfRequested()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 14

Duplication

Lines 21
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 14
nc 1
nop 0
dl 21
loc 21
rs 9.3142
c 0
b 0
f 0
1
<?php
2
namespace ShlinkioTest\Shlink\CLI\Install\Plugin;
3
4
use PHPUnit\Framework\TestCase;
5
use Prophecy\Argument;
6
use Prophecy\Prophecy\MethodProphecy;
7
use Prophecy\Prophecy\ObjectProphecy;
8
use Shlinkio\Shlink\CLI\Install\Plugin\UrlShortenerConfigCustomizerPlugin;
9
use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig;
10
use Symfony\Component\Console\Helper\QuestionHelper;
11
use Symfony\Component\Console\Input\ArrayInput;
12
use Symfony\Component\Console\Output\NullOutput;
13
use Symfony\Component\Console\Question\ConfirmationQuestion;
14
15
class UrlShortenerConfigCustomizerPluginTest extends TestCase
16
{
17
    /**
18
     * @var UrlShortenerConfigCustomizerPlugin
19
     */
20
    private $plugin;
21
    /**
22
     * @var ObjectProphecy
23
     */
24
    private $questionHelper;
25
26
    public function setUp()
27
    {
28
        $this->questionHelper = $this->prophesize(QuestionHelper::class);
29
        $this->plugin = new UrlShortenerConfigCustomizerPlugin($this->questionHelper->reveal());
30
    }
31
32
    /**
33
     * @test
34
     */
35 View Code Duplication
    public function configIsRequestedToTheUser()
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...
36
    {
37
        /** @var MethodProphecy $askSecret */
38
        $askSecret = $this->questionHelper->ask(Argument::cetera())->willReturn('something');
39
        $config = new CustomizableAppConfig();
40
41
        $this->plugin->process(new ArrayInput([]), new NullOutput(), $config);
42
43
        $this->assertTrue($config->hasUrlShortener());
44
        $this->assertEquals([
45
            'SCHEMA' => 'something',
46
            'HOSTNAME' => 'something',
47
            'CHARS' => 'something',
48
        ], $config->getUrlShortener());
49
        $askSecret->shouldHaveBeenCalledTimes(3);
50
    }
51
52
    /**
53
     * @test
54
     */
55
    public function overwriteIsRequestedIfValueIsAlreadySet()
56
    {
57
        /** @var MethodProphecy $ask */
58
        $ask = $this->questionHelper->ask(Argument::cetera())->will(function (array $args) {
59
            $last = array_pop($args);
60
            return $last instanceof ConfirmationQuestion ? false : 'foo';
61
        });
62
        $config = new CustomizableAppConfig();
63
        $config->setUrlShortener([
64
            'SCHEMA' => 'bar',
65
            'HOSTNAME' => 'bar',
66
            'CHARS' => 'bar',
67
        ]);
68
69
        $this->plugin->process(new ArrayInput([]), new NullOutput(), $config);
70
71
        $this->assertEquals([
72
            'SCHEMA' => 'foo',
73
            'HOSTNAME' => 'foo',
74
            'CHARS' => 'foo',
75
        ], $config->getUrlShortener());
76
        $ask->shouldHaveBeenCalledTimes(4);
77
    }
78
79
    /**
80
     * @test
81
     */
82 View Code Duplication
    public function existingValueIsKeptIfRequested()
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...
83
    {
84
        /** @var MethodProphecy $ask */
85
        $ask = $this->questionHelper->ask(Argument::cetera())->willReturn(true);
86
87
        $config = new CustomizableAppConfig();
88
        $config->setUrlShortener([
89
            'SCHEMA' => 'foo',
90
            'HOSTNAME' => 'foo',
91
            'CHARS' => 'foo',
92
        ]);
93
94
        $this->plugin->process(new ArrayInput([]), new NullOutput(), $config);
95
96
        $this->assertEquals([
97
            'SCHEMA' => 'foo',
98
            'HOSTNAME' => 'foo',
99
            'CHARS' => 'foo',
100
        ], $config->getUrlShortener());
101
        $ask->shouldHaveBeenCalledTimes(1);
102
    }
103
}
104