|
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
|
|
|
class LanguageConfigCustomizerTest extends TestCase |
|
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
|
|
View Code Duplication |
public function configIsRequestedToTheUser() |
|
|
|
|
|
|
35
|
|
|
{ |
|
36
|
|
|
$ask = $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
|
|
|
$ask->shouldHaveBeenCalledTimes(2); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @test |
|
51
|
|
|
*/ |
|
52
|
|
View Code Duplication |
public function overwriteIsRequestedIfValueIsAlreadySet() |
|
|
|
|
|
|
53
|
|
|
{ |
|
54
|
|
|
$choice = $this->io->choice(Argument::cetera())->willReturn('es'); |
|
55
|
|
|
$confirm = $this->io->confirm(Argument::cetera())->willReturn(false); |
|
56
|
|
|
$config = new CustomizableAppConfig(); |
|
57
|
|
|
$config->setLanguage([ |
|
58
|
|
|
'DEFAULT' => 'en', |
|
59
|
|
|
'CLI' => 'en', |
|
60
|
|
|
]); |
|
61
|
|
|
|
|
62
|
|
|
$this->plugin->process($this->io->reveal(), $config); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertEquals([ |
|
65
|
|
|
'DEFAULT' => 'es', |
|
66
|
|
|
'CLI' => 'es', |
|
67
|
|
|
], $config->getLanguage()); |
|
68
|
|
|
$choice->shouldHaveBeenCalledTimes(2); |
|
69
|
|
|
$confirm->shouldHaveBeenCalledTimes(1); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @test |
|
74
|
|
|
*/ |
|
75
|
|
|
public function existingValueIsKeptIfRequested() |
|
76
|
|
|
{ |
|
77
|
|
|
$ask = $this->io->confirm(Argument::cetera())->willReturn(true); |
|
78
|
|
|
|
|
79
|
|
|
$config = new CustomizableAppConfig(); |
|
80
|
|
|
$config->setLanguage([ |
|
81
|
|
|
'DEFAULT' => 'es', |
|
82
|
|
|
'CLI' => 'es', |
|
83
|
|
|
]); |
|
84
|
|
|
|
|
85
|
|
|
$this->plugin->process($this->io->reveal(), $config); |
|
86
|
|
|
|
|
87
|
|
|
$this->assertEquals([ |
|
88
|
|
|
'DEFAULT' => 'es', |
|
89
|
|
|
'CLI' => 'es', |
|
90
|
|
|
], $config->getLanguage()); |
|
91
|
|
|
$ask->shouldHaveBeenCalledTimes(1); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
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.