Completed
Push — master ( d5dc6c...9a2ca3 )
by Alejandro
11s
created

overwriteIsRequestedIfValueIsAlreadySet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 25
rs 9.52
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\UrlShortenerConfigCustomizer;
10
use Shlinkio\Shlink\Installer\Model\CustomizableAppConfig;
11
use Symfony\Component\Console\Style\SymfonyStyle;
12
13
class UrlShortenerConfigCustomizerTest extends TestCase
14
{
15
    /**
16
     * @var UrlShortenerConfigCustomizer
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
        $this->plugin = new UrlShortenerConfigCustomizer();
29
    }
30
31
    /**
32
     * @test
33
     */
34
    public function configIsRequestedToTheUser()
35
    {
36
        $choice = $this->io->choice(Argument::cetera())->willReturn('something');
37
        $ask = $this->io->ask(Argument::cetera())->willReturn('something');
38
        $confirm = $this->io->confirm(Argument::cetera())->willReturn(true);
39
        $config = new CustomizableAppConfig();
40
41
        $this->plugin->process($this->io->reveal(), $config);
42
43
        $this->assertTrue($config->hasUrlShortener());
44
        $this->assertEquals([
45
            'SCHEMA' => 'something',
46
            'HOSTNAME' => 'something',
47
            'CHARS' => 'something',
48
            'VALIDATE_URL' => true,
49
        ], $config->getUrlShortener());
50
        $ask->shouldHaveBeenCalledTimes(2);
51
        $choice->shouldHaveBeenCalledTimes(1);
52
        $confirm->shouldHaveBeenCalledTimes(1);
53
    }
54
55
    /**
56
     * @test
57
     */
58
    public function overwriteIsRequestedIfValueIsAlreadySet()
59
    {
60
        $choice = $this->io->choice(Argument::cetera())->willReturn('foo');
61
        $ask = $this->io->ask(Argument::cetera())->willReturn('foo');
62
        $confirm = $this->io->confirm(Argument::cetera())->willReturn(false);
63
        $config = new CustomizableAppConfig();
64
        $config->setUrlShortener([
65
            'SCHEMA' => 'bar',
66
            'HOSTNAME' => 'bar',
67
            'CHARS' => 'bar',
68
            'VALIDATE_URL' => true,
69
        ]);
70
71
        $this->plugin->process($this->io->reveal(), $config);
72
73
        $this->assertEquals([
74
            'SCHEMA' => 'foo',
75
            'HOSTNAME' => 'foo',
76
            'CHARS' => 'foo',
77
            'VALIDATE_URL' => false,
78
        ], $config->getUrlShortener());
79
        $ask->shouldHaveBeenCalledTimes(2);
80
        $choice->shouldHaveBeenCalledTimes(1);
81
        $confirm->shouldHaveBeenCalledTimes(2);
82
    }
83
84
    /**
85
     * @test
86
     */
87
    public function existingValueIsKeptIfRequested()
88
    {
89
        $confirm = $this->io->confirm(Argument::cetera())->willReturn(true);
90
91
        $config = new CustomizableAppConfig();
92
        $config->setUrlShortener([
93
            'SCHEMA' => 'foo',
94
            'HOSTNAME' => 'foo',
95
            'CHARS' => 'foo',
96
            'VALIDATE_URL' => 'foo',
97
        ]);
98
99
        $this->plugin->process($this->io->reveal(), $config);
100
101
        $this->assertEquals([
102
            'SCHEMA' => 'foo',
103
            'HOSTNAME' => 'foo',
104
            'CHARS' => 'foo',
105
            'VALIDATE_URL' => 'foo',
106
        ], $config->getUrlShortener());
107
        $confirm->shouldHaveBeenCalledTimes(1);
108
    }
109
}
110