shlink/module/CLI/test/Command/Install/InstallCommandTest.php

112 lines
3 KiB
PHP
Raw Normal View History

2016-08-15 12:34:35 +03:00
<?php
namespace ShlinkioTest\Shlink\CLI\Command\Install;
2017-03-24 22:34:18 +03:00
use PHPUnit\Framework\TestCase;
2016-08-15 12:34:35 +03:00
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\CLI\Command\Install\InstallCommand;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Helper\ProcessHelper;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Process\Process;
2016-08-15 12:34:35 +03:00
use Zend\Config\Writer\WriterInterface;
class InstallCommandTest extends TestCase
{
/**
* @var CommandTester
*/
protected $commandTester;
/**
* @var ObjectProphecy
*/
protected $configWriter;
public function setUp()
{
$processMock = $this->prophesize(Process::class);
$processMock->isSuccessful()->willReturn(true);
2016-08-15 12:34:35 +03:00
$processHelper = $this->prophesize(ProcessHelper::class);
$processHelper->getName()->willReturn('process');
$processHelper->setHelperSet(Argument::any())->willReturn(null);
$processHelper->run(Argument::cetera())->willReturn($processMock->reveal());
2016-08-15 12:34:35 +03:00
$app = new Application();
$helperSet = $app->getHelperSet();
$helperSet->set($processHelper->reveal());
$app->setHelperSet($helperSet);
$this->configWriter = $this->prophesize(WriterInterface::class);
$command = new InstallCommand($this->configWriter->reveal());
$app->add($command);
$questionHelper = $command->getHelper('question');
$questionHelper->setInputStream($this->createInputStream());
$this->commandTester = new CommandTester($command);
}
protected function createInputStream()
{
2017-01-21 15:33:43 +03:00
$stream = fopen('php://memory', 'rb+', false);
fwrite($stream, <<<CLI_INPUT
2016-08-15 12:34:35 +03:00
shlink_db
alejandro
1234
2016-08-15 12:34:35 +03:00
0
doma.in
abc123BCA
1
my_secret
CLI_INPUT
);
rewind($stream);
return $stream;
}
/**
* @test
*/
2017-01-21 15:33:43 +03:00
public function inputIsProperlyParsed()
2016-08-15 12:34:35 +03:00
{
$this->configWriter->toFile(Argument::any(), [
'app_options' => [
'secret_key' => 'my_secret',
],
'entity_manager' => [
'connection' => [
'driver' => 'pdo_mysql',
'dbname' => 'shlink_db',
'user' => 'alejandro',
'password' => '1234',
'host' => 'localhost',
'port' => '3306',
2017-01-21 15:33:43 +03:00
'driverOptions' => [
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
]
2016-08-15 12:34:35 +03:00
],
],
'translator' => [
'locale' => 'en',
],
'cli' => [
'locale' => 'es',
],
'url_shortener' => [
'domain' => [
'schema' => 'http',
'hostname' => 'doma.in',
],
'shortcode_chars' => 'abc123BCA',
],
], false)->shouldBeCalledTimes(1);
$this->commandTester->execute([
'command' => 'shlink:install',
]);
}
}