Fixed InstallCommandTest

This commit is contained in:
Alejandro Celaya 2017-07-06 10:04:35 +02:00
parent 479e694478
commit 3547889ad5
2 changed files with 37 additions and 58 deletions

View File

@ -4,7 +4,6 @@ namespace Shlinkio\Shlink\CLI\Command\Install;
use Shlinkio\Shlink\CLI\Install\ConfigCustomizerPluginManagerInterface; use Shlinkio\Shlink\CLI\Install\ConfigCustomizerPluginManagerInterface;
use Shlinkio\Shlink\CLI\Install\Plugin; use Shlinkio\Shlink\CLI\Install\Plugin;
use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig; use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig;
use Shlinkio\Shlink\Common\Util\StringUtilsTrait;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Exception\LogicException; use Symfony\Component\Console\Exception\LogicException;
use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Console\Exception\RuntimeException;

View File

@ -5,6 +5,8 @@ use PHPUnit\Framework\TestCase;
use Prophecy\Argument; use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\CLI\Command\Install\InstallCommand; use Shlinkio\Shlink\CLI\Command\Install\InstallCommand;
use Shlinkio\Shlink\CLI\Install\ConfigCustomizerPluginManagerInterface;
use Shlinkio\Shlink\CLI\Install\Plugin\ConfigCustomizerPluginInterface;
use Symfony\Component\Console\Application; use Symfony\Component\Console\Application;
use Symfony\Component\Console\Helper\ProcessHelper; use Symfony\Component\Console\Helper\ProcessHelper;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
@ -39,79 +41,57 @@ class InstallCommandTest extends TestCase
$this->filesystem = $this->prophesize(Filesystem::class); $this->filesystem = $this->prophesize(Filesystem::class);
$this->filesystem->exists(Argument::cetera())->willReturn(false); $this->filesystem->exists(Argument::cetera())->willReturn(false);
$this->configWriter = $this->prophesize(WriterInterface::class);
$configCustomizer = $this->prophesize(ConfigCustomizerPluginInterface::class);
$configCustomizers = $this->prophesize(ConfigCustomizerPluginManagerInterface::class);
$configCustomizers->get(Argument::cetera())->willReturn($configCustomizer->reveal());
$app = new Application(); $app = new Application();
$helperSet = $app->getHelperSet(); $helperSet = $app->getHelperSet();
$helperSet->set($processHelper->reveal()); $helperSet->set($processHelper->reveal());
$app->setHelperSet($helperSet); $app->setHelperSet($helperSet);
$command = new InstallCommand(
$this->configWriter = $this->prophesize(WriterInterface::class); $this->configWriter->reveal(),
$command = new InstallCommand($this->configWriter->reveal(), $this->filesystem->reveal()); $this->filesystem->reveal(),
$configCustomizers->reveal()
);
$app->add($command); $app->add($command);
$questionHelper = $command->getHelper('question'); $questionHelper = $command->getHelper('question');
$questionHelper->setInputStream($this->createInputStream()); // $questionHelper->setInputStream($this->createInputStream());
$this->commandTester = new CommandTester($command); $this->commandTester = new CommandTester($command);
} }
protected function createInputStream() // protected function createInputStream()
{ // {
$stream = fopen('php://memory', 'rb+', false); // $stream = fopen('php://memory', 'rb+', false);
fwrite($stream, <<<CLI_INPUT // fwrite($stream, <<<CLI_INPUT
//
shlink_db //shlink_db
alejandro //alejandro
1234 //1234
//
//
0 //0
doma.in //doma.in
abc123BCA //abc123BCA
//
1 //1
my_secret //my_secret
CLI_INPUT //CLI_INPUT
); // );
rewind($stream); // rewind($stream);
//
return $stream; // return $stream;
} // }
/** /**
* @test * @test
*/ */
public function inputIsProperlyParsed() public function inputIsProperlyParsed()
{ {
$this->configWriter->toFile(Argument::any(), [ $this->configWriter->toFile(Argument::any(), Argument::type('array'), false)->shouldBeCalledTimes(1);
'app_options' => [
'secret_key' => 'my_secret',
],
'entity_manager' => [
'connection' => [
'driver' => 'pdo_mysql',
'dbname' => 'shlink_db',
'user' => 'alejandro',
'password' => '1234',
'host' => 'localhost',
'port' => '3306',
'driverOptions' => [
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
]
],
],
'translator' => [
'locale' => 'en',
],
'cli' => [
'locale' => 'es',
],
'url_shortener' => [
'domain' => [
'schema' => 'http',
'hostname' => 'doma.in',
],
'shortcode_chars' => 'abc123BCA',
],
], false)->shouldBeCalledTimes(1);
$this->commandTester->execute([ $this->commandTester->execute([
'command' => 'shlink:install', 'command' => 'shlink:install',