Completed
Push — master ( 3a75ac...d68dc3 )
by Alejandro
23s
created

  A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 22
rs 9.568
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('chosen');
37
        $ask = $this->io->ask(Argument::cetera())->willReturn('asked');
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' => 'chosen',
46
            'HOSTNAME' => 'asked',
47
            'CHARS' => 'asked',
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 View Code Duplication
    public function onlyMissingOptionsAreAsked()
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...
59
    {
60
        $choice = $this->io->choice(Argument::cetera())->willReturn('chosen');
61
        $ask = $this->io->ask(Argument::cetera())->willReturn('asked');
62
        $confirm = $this->io->confirm(Argument::cetera())->willReturn(false);
63
        $config = new CustomizableAppConfig();
64
        $config->setUrlShortener([
65
            'SCHEMA' => 'foo',
66
            'HOSTNAME' => 'foo',
67
        ]);
68
69
        $this->plugin->process($this->io->reveal(), $config);
70
71
        $this->assertEquals([
72
            'SCHEMA' => 'foo',
73
            'HOSTNAME' => 'foo',
74
            'CHARS' => 'asked',
75
            'VALIDATE_URL' => false,
76
        ], $config->getUrlShortener());
77
        $choice->shouldNotHaveBeenCalled();
78
        $ask->shouldHaveBeenCalledTimes(1);
79
        $confirm->shouldHaveBeenCalledTimes(1);
80
    }
81
82
    /**
83
     * @test
84
     */
85 View Code Duplication
    public function noQuestionsAskedIfImportedConfigContainsEverything()
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...
86
    {
87
        $choice = $this->io->choice(Argument::cetera())->willReturn('chosen');
88
        $ask = $this->io->ask(Argument::cetera())->willReturn('asked');
89
        $confirm = $this->io->confirm(Argument::cetera())->willReturn(false);
90
91
        $config = new CustomizableAppConfig();
92
        $config->setUrlShortener([
93
            'SCHEMA' => 'foo',
94
            'HOSTNAME' => 'foo',
95
            'CHARS' => 'foo',
96
            'VALIDATE_URL' => true,
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' => true,
106
        ], $config->getUrlShortener());
107
        $choice->shouldNotHaveBeenCalled();
108
        $ask->shouldNotHaveBeenCalled();
109
        $confirm->shouldNotHaveBeenCalled();
110
    }
111
}
112