2017-07-06 18:28:32 +03:00
|
|
|
<?php
|
2017-10-12 11:13:20 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2017-07-06 18:28:32 +03:00
|
|
|
namespace ShlinkioTest\Shlink\CLI\Install\Plugin;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Prophecy\Argument;
|
|
|
|
use Prophecy\Prophecy\MethodProphecy;
|
|
|
|
use Prophecy\Prophecy\ObjectProphecy;
|
|
|
|
use Shlinkio\Shlink\CLI\Install\Plugin\UrlShortenerConfigCustomizerPlugin;
|
|
|
|
use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig;
|
|
|
|
use Symfony\Component\Console\Helper\QuestionHelper;
|
|
|
|
use Symfony\Component\Console\Input\ArrayInput;
|
|
|
|
use Symfony\Component\Console\Output\NullOutput;
|
|
|
|
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
|
|
|
|
|
|
|
class UrlShortenerConfigCustomizerPluginTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var UrlShortenerConfigCustomizerPlugin
|
|
|
|
*/
|
|
|
|
private $plugin;
|
|
|
|
/**
|
|
|
|
* @var ObjectProphecy
|
|
|
|
*/
|
|
|
|
private $questionHelper;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
$this->questionHelper = $this->prophesize(QuestionHelper::class);
|
|
|
|
$this->plugin = new UrlShortenerConfigCustomizerPlugin($this->questionHelper->reveal());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function configIsRequestedToTheUser()
|
|
|
|
{
|
|
|
|
/** @var MethodProphecy $askSecret */
|
|
|
|
$askSecret = $this->questionHelper->ask(Argument::cetera())->willReturn('something');
|
|
|
|
$config = new CustomizableAppConfig();
|
|
|
|
|
|
|
|
$this->plugin->process(new ArrayInput([]), new NullOutput(), $config);
|
|
|
|
|
|
|
|
$this->assertTrue($config->hasUrlShortener());
|
|
|
|
$this->assertEquals([
|
|
|
|
'SCHEMA' => 'something',
|
|
|
|
'HOSTNAME' => 'something',
|
|
|
|
'CHARS' => 'something',
|
2017-10-17 12:03:12 +03:00
|
|
|
'VALIDATE_URL' => 'something',
|
2017-07-06 18:28:32 +03:00
|
|
|
], $config->getUrlShortener());
|
2017-10-17 12:03:12 +03:00
|
|
|
$askSecret->shouldHaveBeenCalledTimes(4);
|
2017-07-06 18:28:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function overwriteIsRequestedIfValueIsAlreadySet()
|
|
|
|
{
|
|
|
|
/** @var MethodProphecy $ask */
|
|
|
|
$ask = $this->questionHelper->ask(Argument::cetera())->will(function (array $args) {
|
|
|
|
$last = array_pop($args);
|
|
|
|
return $last instanceof ConfirmationQuestion ? false : 'foo';
|
|
|
|
});
|
|
|
|
$config = new CustomizableAppConfig();
|
|
|
|
$config->setUrlShortener([
|
|
|
|
'SCHEMA' => 'bar',
|
|
|
|
'HOSTNAME' => 'bar',
|
|
|
|
'CHARS' => 'bar',
|
2017-10-17 12:03:12 +03:00
|
|
|
'VALIDATE_URL' => 'bar',
|
2017-07-06 18:28:32 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->plugin->process(new ArrayInput([]), new NullOutput(), $config);
|
|
|
|
|
|
|
|
$this->assertEquals([
|
|
|
|
'SCHEMA' => 'foo',
|
|
|
|
'HOSTNAME' => 'foo',
|
|
|
|
'CHARS' => 'foo',
|
2017-10-17 12:03:12 +03:00
|
|
|
'VALIDATE_URL' => false,
|
2017-07-06 18:28:32 +03:00
|
|
|
], $config->getUrlShortener());
|
2017-10-17 12:03:12 +03:00
|
|
|
$ask->shouldHaveBeenCalledTimes(5);
|
2017-07-06 18:28:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function existingValueIsKeptIfRequested()
|
|
|
|
{
|
|
|
|
/** @var MethodProphecy $ask */
|
|
|
|
$ask = $this->questionHelper->ask(Argument::cetera())->willReturn(true);
|
|
|
|
|
|
|
|
$config = new CustomizableAppConfig();
|
|
|
|
$config->setUrlShortener([
|
|
|
|
'SCHEMA' => 'foo',
|
|
|
|
'HOSTNAME' => 'foo',
|
|
|
|
'CHARS' => 'foo',
|
2017-10-17 12:03:12 +03:00
|
|
|
'VALIDATE_URL' => 'foo',
|
2017-07-06 18:28:32 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->plugin->process(new ArrayInput([]), new NullOutput(), $config);
|
|
|
|
|
|
|
|
$this->assertEquals([
|
|
|
|
'SCHEMA' => 'foo',
|
|
|
|
'HOSTNAME' => 'foo',
|
|
|
|
'CHARS' => 'foo',
|
2017-10-17 12:03:12 +03:00
|
|
|
'VALIDATE_URL' => 'foo',
|
2017-07-06 18:28:32 +03:00
|
|
|
], $config->getUrlShortener());
|
|
|
|
$ask->shouldHaveBeenCalledTimes(1);
|
|
|
|
}
|
|
|
|
}
|