2017-07-06 19:00:38 +03:00
|
|
|
<?php
|
2017-10-12 11:13:20 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2018-09-29 10:52:32 +03:00
|
|
|
namespace ShlinkioTest\Shlink\Installer\Config\Plugin;
|
2017-07-06 19:00:38 +03:00
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Prophecy\Argument;
|
|
|
|
use Prophecy\Prophecy\ObjectProphecy;
|
2018-09-29 10:52:32 +03:00
|
|
|
use Shlinkio\Shlink\Installer\Config\Plugin\DatabaseConfigCustomizer;
|
|
|
|
use Shlinkio\Shlink\Installer\Model\CustomizableAppConfig;
|
2017-12-31 19:14:01 +03:00
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
2017-07-06 19:00:38 +03:00
|
|
|
use Symfony\Component\Filesystem\Filesystem;
|
|
|
|
|
2017-12-31 19:22:25 +03:00
|
|
|
class DatabaseConfigCustomizerTest extends TestCase
|
2017-07-06 19:00:38 +03:00
|
|
|
{
|
|
|
|
/**
|
2017-12-31 19:18:54 +03:00
|
|
|
* @var DatabaseConfigCustomizer
|
2017-07-06 19:00:38 +03:00
|
|
|
*/
|
|
|
|
private $plugin;
|
|
|
|
/**
|
|
|
|
* @var ObjectProphecy
|
|
|
|
*/
|
2017-12-31 19:45:27 +03:00
|
|
|
private $io;
|
2017-07-06 19:00:38 +03:00
|
|
|
/**
|
|
|
|
* @var ObjectProphecy
|
|
|
|
*/
|
|
|
|
private $filesystem;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
2017-12-31 19:45:27 +03:00
|
|
|
$this->io = $this->prophesize(SymfonyStyle::class);
|
|
|
|
$this->io->title(Argument::any())->willReturn(null);
|
2017-07-06 19:00:38 +03:00
|
|
|
$this->filesystem = $this->prophesize(Filesystem::class);
|
|
|
|
|
2017-12-31 19:45:27 +03:00
|
|
|
$this->plugin = new DatabaseConfigCustomizer($this->filesystem->reveal());
|
2017-07-06 19:00:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function configIsRequestedToTheUser()
|
|
|
|
{
|
2017-12-31 19:45:27 +03:00
|
|
|
$choice = $this->io->choice(Argument::cetera())->willReturn('MySQL');
|
|
|
|
$ask = $this->io->ask(Argument::cetera())->willReturn('param');
|
2017-07-06 19:00:38 +03:00
|
|
|
$config = new CustomizableAppConfig();
|
|
|
|
|
2017-12-31 19:45:27 +03:00
|
|
|
$this->plugin->process($this->io->reveal(), $config);
|
2017-07-06 19:00:38 +03:00
|
|
|
|
|
|
|
$this->assertTrue($config->hasDatabase());
|
|
|
|
$this->assertEquals([
|
|
|
|
'DRIVER' => 'pdo_mysql',
|
2017-12-31 19:45:27 +03:00
|
|
|
'NAME' => 'param',
|
|
|
|
'USER' => 'param',
|
|
|
|
'PASSWORD' => 'param',
|
|
|
|
'HOST' => 'param',
|
|
|
|
'PORT' => 'param',
|
2017-07-06 19:00:38 +03:00
|
|
|
], $config->getDatabase());
|
2017-12-31 19:45:27 +03:00
|
|
|
$choice->shouldHaveBeenCalledTimes(1);
|
|
|
|
$ask->shouldHaveBeenCalledTimes(5);
|
2017-07-06 19:00:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function overwriteIsRequestedIfValueIsAlreadySet()
|
|
|
|
{
|
2017-12-31 19:45:27 +03:00
|
|
|
$choice = $this->io->choice(Argument::cetera())->willReturn('MySQL');
|
|
|
|
$confirm = $this->io->confirm(Argument::cetera())->willReturn(false);
|
|
|
|
$ask = $this->io->ask(Argument::cetera())->willReturn('MySQL');
|
2017-07-06 19:00:38 +03:00
|
|
|
$config = new CustomizableAppConfig();
|
|
|
|
$config->setDatabase([
|
|
|
|
'DRIVER' => 'pdo_pgsql',
|
|
|
|
'NAME' => 'MySQL',
|
|
|
|
'USER' => 'MySQL',
|
|
|
|
'PASSWORD' => 'MySQL',
|
|
|
|
'HOST' => 'MySQL',
|
|
|
|
'PORT' => 'MySQL',
|
|
|
|
]);
|
|
|
|
|
2017-12-31 19:45:27 +03:00
|
|
|
$this->plugin->process($this->io->reveal(), $config);
|
2017-07-06 19:00:38 +03:00
|
|
|
|
|
|
|
$this->assertEquals([
|
|
|
|
'DRIVER' => 'pdo_mysql',
|
|
|
|
'NAME' => 'MySQL',
|
|
|
|
'USER' => 'MySQL',
|
|
|
|
'PASSWORD' => 'MySQL',
|
|
|
|
'HOST' => 'MySQL',
|
|
|
|
'PORT' => 'MySQL',
|
|
|
|
], $config->getDatabase());
|
2017-12-31 19:45:27 +03:00
|
|
|
$confirm->shouldHaveBeenCalledTimes(1);
|
|
|
|
$choice->shouldHaveBeenCalledTimes(1);
|
|
|
|
$ask->shouldHaveBeenCalledTimes(5);
|
2017-07-06 19:00:38 +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 19:00:38 +03:00
|
|
|
|
|
|
|
$config = new CustomizableAppConfig();
|
|
|
|
$config->setDatabase([
|
|
|
|
'DRIVER' => 'pdo_pgsql',
|
|
|
|
'NAME' => 'MySQL',
|
|
|
|
'USER' => 'MySQL',
|
|
|
|
'PASSWORD' => 'MySQL',
|
|
|
|
'HOST' => 'MySQL',
|
|
|
|
'PORT' => 'MySQL',
|
|
|
|
]);
|
|
|
|
|
2017-12-31 19:45:27 +03:00
|
|
|
$this->plugin->process($this->io->reveal(), $config);
|
2017-07-06 19:00:38 +03:00
|
|
|
|
|
|
|
$this->assertEquals([
|
|
|
|
'DRIVER' => 'pdo_pgsql',
|
|
|
|
'NAME' => 'MySQL',
|
|
|
|
'USER' => 'MySQL',
|
|
|
|
'PASSWORD' => 'MySQL',
|
|
|
|
'HOST' => 'MySQL',
|
|
|
|
'PORT' => 'MySQL',
|
|
|
|
], $config->getDatabase());
|
2017-12-31 19:45:27 +03:00
|
|
|
$confirm->shouldHaveBeenCalledTimes(1);
|
2017-07-06 19:00:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function sqliteDatabaseIsImportedWhenRequested()
|
|
|
|
{
|
2017-12-31 19:45:27 +03:00
|
|
|
$confirm = $this->io->confirm(Argument::cetera())->willReturn(true);
|
2017-07-06 19:00:38 +03:00
|
|
|
$copy = $this->filesystem->copy(Argument::cetera())->willReturn(null);
|
|
|
|
|
|
|
|
$config = new CustomizableAppConfig();
|
|
|
|
$config->setDatabase([
|
|
|
|
'DRIVER' => 'pdo_sqlite',
|
|
|
|
]);
|
|
|
|
|
2017-12-31 19:45:27 +03:00
|
|
|
$this->plugin->process($this->io->reveal(), $config);
|
2017-07-06 19:00:38 +03:00
|
|
|
|
|
|
|
$this->assertEquals([
|
|
|
|
'DRIVER' => 'pdo_sqlite',
|
|
|
|
], $config->getDatabase());
|
2017-12-31 19:45:27 +03:00
|
|
|
$confirm->shouldHaveBeenCalledTimes(1);
|
2017-07-06 19:00:38 +03:00
|
|
|
$copy->shouldHaveBeenCalledTimes(1);
|
|
|
|
}
|
|
|
|
}
|