Completed
Pull Request — master (#224)
by Alejandro
03:14
created

LanguageConfigCustomizerTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 78
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 78
loc 78
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A configIsRequestedToTheUser() 14 14 1
A setUp() 6 6 1
A onlyMissingOptionsAreAsked() 16 16 1
A noQuestionsAskedIfImportedConfigContainsEverything() 18 18 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\LanguageConfigCustomizer;
10
use Shlinkio\Shlink\Installer\Model\CustomizableAppConfig;
11
use Symfony\Component\Console\Style\SymfonyStyle;
12
13 View Code Duplication
class LanguageConfigCustomizerTest extends TestCase
0 ignored issues
show
Duplication introduced by
This class 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...
14
{
15
    /**
16
     * @var LanguageConfigCustomizer
17
     */
18
    protected $plugin;
19
    /**
20
     * @var ObjectProphecy
21
     */
22
    protected $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 LanguageConfigCustomizer();
29
    }
30
31
    /**
32
     * @test
33
     */
34
    public function configIsRequestedToTheUser()
35
    {
36
        $choice = $this->io->choice(Argument::cetera())->willReturn('en');
37
        $config = new CustomizableAppConfig();
38
39
        $this->plugin->process($this->io->reveal(), $config);
40
41
        $this->assertTrue($config->hasLanguage());
42
        $this->assertEquals([
43
            'DEFAULT' => 'en',
44
            'CLI' => 'en',
45
        ], $config->getLanguage());
46
        $choice->shouldHaveBeenCalledTimes(2);
47
    }
48
49
    /**
50
     * @test
51
     */
52
    public function onlyMissingOptionsAreAsked()
53
    {
54
        $choice = $this->io->choice(Argument::cetera())->willReturn('es');
55
        $config = new CustomizableAppConfig();
56
        $config->setLanguage([
57
            'DEFAULT' => 'en',
58
        ]);
59
60
        $this->plugin->process($this->io->reveal(), $config);
61
62
        $this->assertEquals([
63
            'DEFAULT' => 'en',
64
            'CLI' => 'es',
65
        ], $config->getLanguage());
66
        $choice->shouldHaveBeenCalledTimes(1);
67
    }
68
69
    /**
70
     * @test
71
     */
72
    public function noQuestionsAskedIfImportedConfigContainsEverything()
73
    {
74
        $choice = $this->io->choice(Argument::cetera())->willReturn('en');
75
76
        $config = new CustomizableAppConfig();
77
        $config->setLanguage([
78
            'DEFAULT' => 'es',
79
            'CLI' => 'es',
80
        ]);
81
82
        $this->plugin->process($this->io->reveal(), $config);
83
84
        $this->assertEquals([
85
            'DEFAULT' => 'es',
86
            'CLI' => 'es',
87
        ], $config->getLanguage());
88
        $choice->shouldNotHaveBeenCalled();
89
    }
90
}
91