Completed
Pull Request — master (#220)
by Alejandro
03:52
created

overwriteIsRequestedIfValueIsAlreadySet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 18
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 18
loc 18
rs 9.6666
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace ShlinkioTest\Shlink\Installer\Config\Plugin;
5
6
use PHPUnit\Framework\TestCase;
7
use Prophecy\Argument;
8
use Prophecy\Prophecy\ObjectProphecy;
9
use Shlinkio\Shlink\Installer\Config\Plugin\ApplicationConfigCustomizer;
10
use Shlinkio\Shlink\Installer\Model\CustomizableAppConfig;
11
use Symfony\Component\Console\Style\SymfonyStyle;
12
13
class ApplicationConfigCustomizerTest extends TestCase
14
{
15
    /**
16
     * @var ApplicationConfigCustomizer
17
     */
18
    private $plugin;
19
    /**
20
     * @var ObjectProphecy
21
     */
22
    private $io;
23
24
    public function setUp()
25
    {
26
        $this->io = $this->prophesize(SymfonyStyle::class);
27
        $this->io->title(Argument::any())->willReturn(null);
28
29
        $this->plugin = new ApplicationConfigCustomizer();
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
        $ask = $this->io->ask(Argument::cetera())->willReturn('the_secret');
38
        $config = new CustomizableAppConfig();
39
40
        $this->plugin->process($this->io->reveal(), $config);
41
42
        $this->assertTrue($config->hasApp());
43
        $this->assertEquals([
44
            'SECRET' => 'the_secret',
45
            'DISABLE_TRACK_PARAM' => 'the_secret',
46
        ], $config->getApp());
47
        $ask->shouldHaveBeenCalledTimes(2);
48
    }
49
50
    /**
51
     * @test
52
     */
53 View Code Duplication
    public function overwriteIsRequestedIfValueIsAlreadySet()
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...
54
    {
55
        $ask = $this->io->ask(Argument::cetera())->willReturn('the_new_secret');
56
        $confirm = $this->io->confirm(Argument::cetera())->willReturn(false);
57
        $config = new CustomizableAppConfig();
58
        $config->setApp([
59
            'SECRET' => 'foo',
60
        ]);
61
62
        $this->plugin->process($this->io->reveal(), $config);
63
64
        $this->assertEquals([
65
            'SECRET' => 'the_new_secret',
66
            'DISABLE_TRACK_PARAM' => 'the_new_secret',
67
        ], $config->getApp());
68
        $ask->shouldHaveBeenCalledTimes(2);
69
        $confirm->shouldHaveBeenCalledTimes(1);
70
    }
71
72
    /**
73
     * @test
74
     */
75 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...
76
    {
77
        $confirm = $this->io->confirm(Argument::cetera())->willReturn(true);
78
79
        $config = new CustomizableAppConfig();
80
        $config->setApp([
81
            'SECRET' => 'foo',
82
        ]);
83
84
        $this->plugin->process($this->io->reveal(), $config);
85
86
        $this->assertEquals([
87
            'SECRET' => 'foo',
88
        ], $config->getApp());
89
        $confirm->shouldHaveBeenCalledTimes(1);
90
    }
91
}
92