shlink/module/Installer/test/Config/Plugin/ApplicationConfigCustomizerTest.php

92 lines
2.4 KiB
PHP
Raw Normal View History

<?php
2017-10-12 11:13:20 +03:00
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Installer\Config\Plugin;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\Installer\Config\Plugin\ApplicationConfigCustomizer;
use Shlinkio\Shlink\Installer\Model\CustomizableAppConfig;
use Symfony\Component\Console\Style\SymfonyStyle;
2017-12-31 19:22:25 +03:00
class ApplicationConfigCustomizerTest extends TestCase
{
/**
* @var ApplicationConfigCustomizer
*/
private $plugin;
/**
* @var ObjectProphecy
*/
2017-12-31 19:45:27 +03:00
private $io;
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();
}
/**
* @test
*/
public function configIsRequestedToTheUser()
{
$ask = $this->io->ask(Argument::cetera())->willReturn('the_secret');
$config = new CustomizableAppConfig();
2017-12-31 19:45:27 +03:00
$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
*/
2018-10-06 11:05:25 +03:00
public function onlyMissingOptionsAreAsked()
{
2018-10-06 11:05:25 +03:00
$ask = $this->io->ask(Argument::cetera())->willReturn('disable_param');
$config = new CustomizableAppConfig();
$config->setApp([
'SECRET' => 'foo',
]);
2017-12-31 19:45:27 +03:00
$this->plugin->process($this->io->reveal(), $config);
$this->assertEquals([
2018-10-06 11:05:25 +03:00
'SECRET' => 'foo',
'DISABLE_TRACK_PARAM' => 'disable_param',
], $config->getApp());
2018-10-06 11:05:25 +03:00
$ask->shouldHaveBeenCalledTimes(1);
}
/**
* @test
*/
2018-10-06 11:05:25 +03:00
public function noQuestionsAskedIfImportedConfigContainsEverything()
{
2018-10-06 11:05:25 +03:00
$ask = $this->io->ask(Argument::cetera())->willReturn('the_new_secret');
$config = new CustomizableAppConfig();
$config->setApp([
'SECRET' => 'foo',
'DISABLE_TRACK_PARAM' => 'the_new_secret',
]);
2017-12-31 19:45:27 +03:00
$this->plugin->process($this->io->reveal(), $config);
$this->assertEquals([
'SECRET' => 'foo',
'DISABLE_TRACK_PARAM' => 'the_new_secret',
], $config->getApp());
2018-10-06 11:05:25 +03:00
$ask->shouldNotHaveBeenCalled();
}
}