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;
|
2017-07-06 11:04:35 +03:00
|
|
|
use Shlinkio\Shlink\CLI\Install\ConfigCustomizerPluginManagerInterface;
|
|
|
|
use Shlinkio\Shlink\CLI\Install\Plugin\ConfigCustomizerPluginInterface;
|
2016-08-15 12:34:35 +03:00
|
|
|
use Symfony\Component\Console\Application;
|
|
|
|
use Symfony\Component\Console\Helper\ProcessHelper;
|
|
|
|
use Symfony\Component\Console\Tester\CommandTester;
|
2017-07-04 21:14:22 +03:00
|
|
|
use Symfony\Component\Filesystem\Filesystem;
|
2016-08-18 19:02:24 +03:00
|
|
|
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;
|
2017-07-04 21:14:22 +03:00
|
|
|
/**
|
|
|
|
* @var ObjectProphecy
|
|
|
|
*/
|
|
|
|
protected $filesystem;
|
2016-08-15 12:34:35 +03:00
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
2016-08-18 19:02:24 +03:00
|
|
|
$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);
|
2016-08-18 19:02:24 +03:00
|
|
|
$processHelper->run(Argument::cetera())->willReturn($processMock->reveal());
|
2016-08-15 12:34:35 +03:00
|
|
|
|
2017-07-04 21:14:22 +03:00
|
|
|
$this->filesystem = $this->prophesize(Filesystem::class);
|
|
|
|
$this->filesystem->exists(Argument::cetera())->willReturn(false);
|
|
|
|
|
2017-07-06 11:04:35 +03:00
|
|
|
$this->configWriter = $this->prophesize(WriterInterface::class);
|
|
|
|
|
|
|
|
$configCustomizer = $this->prophesize(ConfigCustomizerPluginInterface::class);
|
|
|
|
$configCustomizers = $this->prophesize(ConfigCustomizerPluginManagerInterface::class);
|
|
|
|
$configCustomizers->get(Argument::cetera())->willReturn($configCustomizer->reveal());
|
|
|
|
|
2016-08-15 12:34:35 +03:00
|
|
|
$app = new Application();
|
|
|
|
$helperSet = $app->getHelperSet();
|
|
|
|
$helperSet->set($processHelper->reveal());
|
|
|
|
$app->setHelperSet($helperSet);
|
2017-07-06 11:04:35 +03:00
|
|
|
$command = new InstallCommand(
|
|
|
|
$this->configWriter->reveal(),
|
|
|
|
$this->filesystem->reveal(),
|
|
|
|
$configCustomizers->reveal()
|
|
|
|
);
|
2016-08-15 12:34:35 +03:00
|
|
|
$app->add($command);
|
|
|
|
|
|
|
|
$questionHelper = $command->getHelper('question');
|
2017-07-06 11:04:35 +03:00
|
|
|
// $questionHelper->setInputStream($this->createInputStream());
|
2016-08-15 12:34:35 +03:00
|
|
|
$this->commandTester = new CommandTester($command);
|
|
|
|
}
|
|
|
|
|
2017-07-06 11:04:35 +03:00
|
|
|
// protected function createInputStream()
|
|
|
|
// {
|
|
|
|
// $stream = fopen('php://memory', 'rb+', false);
|
|
|
|
// fwrite($stream, <<<CLI_INPUT
|
|
|
|
//
|
|
|
|
//shlink_db
|
|
|
|
//alejandro
|
|
|
|
//1234
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//0
|
|
|
|
//doma.in
|
|
|
|
//abc123BCA
|
|
|
|
//
|
|
|
|
//1
|
|
|
|
//my_secret
|
|
|
|
//CLI_INPUT
|
|
|
|
// );
|
|
|
|
// rewind($stream);
|
|
|
|
//
|
|
|
|
// return $stream;
|
|
|
|
// }
|
2016-08-15 12:34:35 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2017-01-21 15:33:43 +03:00
|
|
|
public function inputIsProperlyParsed()
|
2016-08-15 12:34:35 +03:00
|
|
|
{
|
2017-07-06 11:04:35 +03:00
|
|
|
$this->configWriter->toFile(Argument::any(), Argument::type('array'), false)->shouldBeCalledTimes(1);
|
2017-07-03 21:46:35 +03:00
|
|
|
|
2016-08-15 12:34:35 +03:00
|
|
|
$this->commandTester->execute([
|
|
|
|
'command' => 'shlink:install',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|