shlink/module/CLI/test/Install/Plugin/LanguageConfigCustomizerTest.php

94 lines
2.4 KiB
PHP
Raw Normal View History

<?php
2017-10-12 03:13:20 -05:00
declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Install\Plugin;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\CLI\Install\Plugin\LanguageConfigCustomizer;
use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig;
use Symfony\Component\Console\Style\SymfonyStyle;
2017-12-31 10:22:25 -06:00
class LanguageConfigCustomizerTest extends TestCase
{
/**
* @var LanguageConfigCustomizer
*/
protected $plugin;
/**
* @var ObjectProphecy
*/
2017-12-31 10:45:27 -06:00
protected $io;
public function setUp()
{
2017-12-31 10:45:27 -06:00
$this->io = $this->prophesize(SymfonyStyle::class);
$this->io->title(Argument::any())->willReturn(null);
$this->plugin = new LanguageConfigCustomizer();
}
/**
* @test
*/
public function configIsRequestedToTheUser()
{
2017-12-31 10:45:27 -06:00
$ask = $this->io->choice(Argument::cetera())->willReturn('en');
$config = new CustomizableAppConfig();
2017-12-31 10:45:27 -06:00
$this->plugin->process($this->io->reveal(), $config);
$this->assertTrue($config->hasLanguage());
$this->assertEquals([
'DEFAULT' => 'en',
'CLI' => 'en',
], $config->getLanguage());
2017-12-31 10:45:27 -06:00
$ask->shouldHaveBeenCalledTimes(2);
}
/**
* @test
*/
public function overwriteIsRequestedIfValueIsAlreadySet()
{
2017-12-31 10:45:27 -06:00
$choice = $this->io->choice(Argument::cetera())->willReturn('es');
$confirm = $this->io->confirm(Argument::cetera())->willReturn(false);
$config = new CustomizableAppConfig();
$config->setLanguage([
'DEFAULT' => 'en',
'CLI' => 'en',
]);
2017-12-31 10:45:27 -06:00
$this->plugin->process($this->io->reveal(), $config);
$this->assertEquals([
'DEFAULT' => 'es',
'CLI' => 'es',
], $config->getLanguage());
2017-12-31 10:45:27 -06:00
$choice->shouldHaveBeenCalledTimes(2);
$confirm->shouldHaveBeenCalledTimes(1);
}
/**
* @test
*/
public function existingValueIsKeptIfRequested()
{
2017-12-31 10:45:27 -06:00
$ask = $this->io->confirm(Argument::cetera())->willReturn(true);
$config = new CustomizableAppConfig();
$config->setLanguage([
'DEFAULT' => 'es',
'CLI' => 'es',
]);
2017-12-31 10:45:27 -06:00
$this->plugin->process($this->io->reveal(), $config);
$this->assertEquals([
'DEFAULT' => 'es',
'CLI' => 'es',
], $config->getLanguage());
$ask->shouldHaveBeenCalledTimes(1);
}
}