| @@ 13-91 (lines=79) @@ | ||
| 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 | public function configIsRequestedToTheUser() |
|
| 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 | public function onlyMissingOptionsAreAsked() |
|
| 54 | { |
|
| 55 | $ask = $this->io->ask(Argument::cetera())->willReturn('disable_param'); |
|
| 56 | $config = new CustomizableAppConfig(); |
|
| 57 | $config->setApp([ |
|
| 58 | 'SECRET' => 'foo', |
|
| 59 | ]); |
|
| 60 | ||
| 61 | $this->plugin->process($this->io->reveal(), $config); |
|
| 62 | ||
| 63 | $this->assertEquals([ |
|
| 64 | 'SECRET' => 'foo', |
|
| 65 | 'DISABLE_TRACK_PARAM' => 'disable_param', |
|
| 66 | ], $config->getApp()); |
|
| 67 | $ask->shouldHaveBeenCalledTimes(1); |
|
| 68 | } |
|
| 69 | ||
| 70 | /** |
|
| 71 | * @test |
|
| 72 | */ |
|
| 73 | public function noQuestionsAskedIfImportedConfigContainsEverything() |
|
| 74 | { |
|
| 75 | $ask = $this->io->ask(Argument::cetera())->willReturn('the_new_secret'); |
|
| 76 | ||
| 77 | $config = new CustomizableAppConfig(); |
|
| 78 | $config->setApp([ |
|
| 79 | 'SECRET' => 'foo', |
|
| 80 | 'DISABLE_TRACK_PARAM' => 'the_new_secret', |
|
| 81 | ]); |
|
| 82 | ||
| 83 | $this->plugin->process($this->io->reveal(), $config); |
|
| 84 | ||
| 85 | $this->assertEquals([ |
|
| 86 | 'SECRET' => 'foo', |
|
| 87 | 'DISABLE_TRACK_PARAM' => 'the_new_secret', |
|
| 88 | ], $config->getApp()); |
|
| 89 | $ask->shouldNotHaveBeenCalled(); |
|
| 90 | } |
|
| 91 | } |
|
| 92 | ||
| @@ 13-90 (lines=78) @@ | ||
| 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 | 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 | ||