mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-28 17:08:58 +03:00
91 lines
2.4 KiB
PHP
91 lines
2.4 KiB
PHP
<?php
|
|
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\ApplicationConfigCustomizer;
|
|
use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig;
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
|
|
|
class ApplicationConfigCustomizerTest extends TestCase
|
|
{
|
|
/**
|
|
* @var ApplicationConfigCustomizer
|
|
*/
|
|
private $plugin;
|
|
/**
|
|
* @var ObjectProphecy
|
|
*/
|
|
private $io;
|
|
|
|
public function setUp()
|
|
{
|
|
$this->io = $this->prophesize(SymfonyStyle::class);
|
|
$this->io->title(Argument::any())->willReturn(null);
|
|
|
|
$this->plugin = new ApplicationConfigCustomizer();
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function configIsRequestedToTheUser()
|
|
{
|
|
$ask = $this->io->ask(Argument::cetera())->willReturn('the_secret');
|
|
$config = new CustomizableAppConfig();
|
|
|
|
$this->plugin->process($this->io->reveal(), $config);
|
|
|
|
$this->assertTrue($config->hasApp());
|
|
$this->assertEquals([
|
|
'SECRET' => 'the_secret',
|
|
'DISABLE_TRACK_PARAM' => 'the_secret',
|
|
], $config->getApp());
|
|
$ask->shouldHaveBeenCalledTimes(2);
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function overwriteIsRequestedIfValueIsAlreadySet()
|
|
{
|
|
$ask = $this->io->ask(Argument::cetera())->willReturn('the_new_secret');
|
|
$confirm = $this->io->confirm(Argument::cetera())->willReturn(false);
|
|
$config = new CustomizableAppConfig();
|
|
$config->setApp([
|
|
'SECRET' => 'foo',
|
|
]);
|
|
|
|
$this->plugin->process($this->io->reveal(), $config);
|
|
|
|
$this->assertEquals([
|
|
'SECRET' => 'the_new_secret',
|
|
'DISABLE_TRACK_PARAM' => 'the_new_secret',
|
|
], $config->getApp());
|
|
$ask->shouldHaveBeenCalledTimes(2);
|
|
$confirm->shouldHaveBeenCalledTimes(1);
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function existingValueIsKeptIfRequested()
|
|
{
|
|
$confirm = $this->io->confirm(Argument::cetera())->willReturn(true);
|
|
|
|
$config = new CustomizableAppConfig();
|
|
$config->setApp([
|
|
'SECRET' => 'foo',
|
|
]);
|
|
|
|
$this->plugin->process($this->io->reveal(), $config);
|
|
|
|
$this->assertEquals([
|
|
'SECRET' => 'foo',
|
|
], $config->getApp());
|
|
$confirm->shouldHaveBeenCalledTimes(1);
|
|
}
|
|
}
|