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

overwriteIsRequestedIfValueIsAlreadySet()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 14
nc 1
nop 0
dl 0
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\LanguageConfigCustomizerPlugin;
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 LanguageConfigCustomizerPluginTest extends TestCase
16
{
17
    /**
18
     * @var LanguageConfigCustomizerPlugin
19
     */
20
    protected $plugin;
21
    /**
22
     * @var ObjectProphecy
23
     */
24
    protected $questionHelper;
25
26
    public function setUp()
27
    {
28
        $this->questionHelper = $this->prophesize(QuestionHelper::class);
29
        $this->plugin = new LanguageConfigCustomizerPlugin($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('en');
39
        $config = new CustomizableAppConfig();
40
41
        $this->plugin->process(new ArrayInput([]), new NullOutput(), $config);
42
43
        $this->assertTrue($config->hasLanguage());
44
        $this->assertEquals([
45
            'DEFAULT' => 'en',
46
            'CLI' => 'en',
47
        ], $config->getLanguage());
48
        $askSecret->shouldHaveBeenCalledTimes(2);
49
    }
50
51
    /**
52
     * @test
53
     */
54
    public function overwriteIsRequestedIfValueIsAlreadySet()
55
    {
56
        /** @var MethodProphecy $ask */
57
        $ask = $this->questionHelper->ask(Argument::cetera())->will(function (array $args) {
58
            $last = array_pop($args);
59
            return $last instanceof ConfirmationQuestion ? false : 'es';
60
        });
61
        $config = new CustomizableAppConfig();
62
        $config->setLanguage([
63
            'DEFAULT' => 'en',
64
            'CLI' => 'en',
65
        ]);
66
67
        $this->plugin->process(new ArrayInput([]), new NullOutput(), $config);
68
69
        $this->assertEquals([
70
            'DEFAULT' => 'es',
71
            'CLI' => 'es',
72
        ], $config->getLanguage());
73
        $ask->shouldHaveBeenCalledTimes(3);
74
    }
75
76
    /**
77
     * @test
78
     */
79 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...
80
    {
81
        /** @var MethodProphecy $ask */
82
        $ask = $this->questionHelper->ask(Argument::cetera())->willReturn(true);
83
84
        $config = new CustomizableAppConfig();
85
        $config->setLanguage([
86
            'DEFAULT' => 'es',
87
            'CLI' => 'es',
88
        ]);
89
90
        $this->plugin->process(new ArrayInput([]), new NullOutput(), $config);
91
92
        $this->assertEquals([
93
            'DEFAULT' => 'es',
94
            'CLI' => 'es',
95
        ], $config->getLanguage());
96
        $ask->shouldHaveBeenCalledTimes(1);
97
    }
98
}
99