2017-07-06 18:12:19 +03:00
|
|
|
<?php
|
2017-10-12 11:13:20 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2017-07-06 18:12:19 +03:00
|
|
|
namespace ShlinkioTest\Shlink\CLI\Install\Plugin;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Prophecy\Argument;
|
|
|
|
use Prophecy\Prophecy\ObjectProphecy;
|
2017-12-31 19:18:54 +03:00
|
|
|
use Shlinkio\Shlink\CLI\Install\Plugin\ApplicationConfigCustomizer;
|
2017-07-06 18:12:19 +03:00
|
|
|
use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig;
|
2017-12-31 19:14:01 +03:00
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
2017-07-06 18:12:19 +03:00
|
|
|
|
2017-12-31 19:22:25 +03:00
|
|
|
class ApplicationConfigCustomizerTest extends TestCase
|
2017-07-06 18:12:19 +03:00
|
|
|
{
|
|
|
|
/**
|
2017-12-31 19:18:54 +03:00
|
|
|
* @var ApplicationConfigCustomizer
|
2017-07-06 18:12:19 +03:00
|
|
|
*/
|
|
|
|
private $plugin;
|
|
|
|
/**
|
|
|
|
* @var ObjectProphecy
|
|
|
|
*/
|
2017-12-31 19:45:27 +03:00
|
|
|
private $io;
|
2017-07-06 18:12:19 +03:00
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
2017-12-31 19:45:27 +03:00
|
|
|
$this->io = $this->prophesize(SymfonyStyle::class);
|
|
|
|
$this->io->title(Argument::any())->willReturn(null);
|
|
|
|
|
|
|
|
$this->plugin = new ApplicationConfigCustomizer();
|
2017-07-06 18:12:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function configIsRequestedToTheUser()
|
|
|
|
{
|
2017-12-31 19:45:27 +03:00
|
|
|
$askSecret = $this->io->ask(Argument::cetera())->willReturn('the_secret');
|
2017-07-06 18:12:19 +03:00
|
|
|
$config = new CustomizableAppConfig();
|
|
|
|
|
2017-12-31 19:45:27 +03:00
|
|
|
$this->plugin->process($this->io->reveal(), $config);
|
2017-07-06 18:12:19 +03:00
|
|
|
|
|
|
|
$this->assertTrue($config->hasApp());
|
|
|
|
$this->assertEquals([
|
|
|
|
'SECRET' => 'the_secret',
|
|
|
|
], $config->getApp());
|
|
|
|
$askSecret->shouldHaveBeenCalledTimes(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function overwriteIsRequestedIfValueIsAlreadySet()
|
|
|
|
{
|
2017-12-31 19:45:27 +03:00
|
|
|
$ask = $this->io->ask(Argument::cetera())->willReturn('the_new_secret');
|
|
|
|
$confirm = $this->io->confirm(Argument::cetera())->willReturn(false);
|
2017-07-06 18:12:19 +03:00
|
|
|
$config = new CustomizableAppConfig();
|
|
|
|
$config->setApp([
|
|
|
|
'SECRET' => 'foo',
|
|
|
|
]);
|
|
|
|
|
2017-12-31 19:45:27 +03:00
|
|
|
$this->plugin->process($this->io->reveal(), $config);
|
2017-07-06 18:12:19 +03:00
|
|
|
|
|
|
|
$this->assertEquals([
|
|
|
|
'SECRET' => 'the_new_secret',
|
|
|
|
], $config->getApp());
|
2017-12-31 19:45:27 +03:00
|
|
|
$ask->shouldHaveBeenCalledTimes(1);
|
|
|
|
$confirm->shouldHaveBeenCalledTimes(1);
|
2017-07-06 18:12:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function existingValueIsKeptIfRequested()
|
|
|
|
{
|
2017-12-31 19:45:27 +03:00
|
|
|
$confirm = $this->io->confirm(Argument::cetera())->willReturn(true);
|
2017-07-06 18:12:19 +03:00
|
|
|
|
|
|
|
$config = new CustomizableAppConfig();
|
|
|
|
$config->setApp([
|
|
|
|
'SECRET' => 'foo',
|
|
|
|
]);
|
|
|
|
|
2017-12-31 19:45:27 +03:00
|
|
|
$this->plugin->process($this->io->reveal(), $config);
|
2017-07-06 18:12:19 +03:00
|
|
|
|
|
|
|
$this->assertEquals([
|
|
|
|
'SECRET' => 'foo',
|
|
|
|
], $config->getApp());
|
2017-12-31 19:45:27 +03:00
|
|
|
$confirm->shouldHaveBeenCalledTimes(1);
|
2017-07-06 18:12:19 +03:00
|
|
|
}
|
|
|
|
}
|