mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Improved InstallCommandTest coverage
This commit is contained in:
@@ -158,7 +158,7 @@ class InstallCommand extends Command
|
|||||||
* @return CustomizableAppConfig
|
* @return CustomizableAppConfig
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
*/
|
*/
|
||||||
protected function importConfig()
|
private function importConfig()
|
||||||
{
|
{
|
||||||
$config = new CustomizableAppConfig();
|
$config = new CustomizableAppConfig();
|
||||||
|
|
||||||
@@ -204,7 +204,7 @@ class InstallCommand extends Command
|
|||||||
* @return string
|
* @return string
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
*/
|
*/
|
||||||
protected function ask($text, $default = null, $allowEmpty = false)
|
private function ask($text, $default = null, $allowEmpty = false)
|
||||||
{
|
{
|
||||||
if ($default !== null) {
|
if ($default !== null) {
|
||||||
$text .= ' (defaults to ' . $default . ')';
|
$text .= ' (defaults to ' . $default . ')';
|
||||||
@@ -227,7 +227,7 @@ class InstallCommand extends Command
|
|||||||
* @param string $errorMessage
|
* @param string $errorMessage
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function runCommand($command, $errorMessage)
|
private function runCommand($command, $errorMessage)
|
||||||
{
|
{
|
||||||
$process = $this->processHelper->run($this->output, $command);
|
$process = $this->processHelper->run($this->output, $command);
|
||||||
if ($process->isSuccessful()) {
|
if ($process->isSuccessful()) {
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
<?php
|
||||||
|
return [];
|
||||||
@@ -3,6 +3,7 @@ namespace ShlinkioTest\Shlink\CLI\Command\Install;
|
|||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Prophecy\Argument;
|
use Prophecy\Argument;
|
||||||
|
use Prophecy\Prophecy\MethodProphecy;
|
||||||
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\ConfigCustomizerPluginManagerInterface;
|
||||||
@@ -10,12 +11,17 @@ 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;
|
||||||
|
use Symfony\Component\Filesystem\Exception\IOException;
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
use Zend\Config\Writer\WriterInterface;
|
use Zend\Config\Writer\WriterInterface;
|
||||||
|
|
||||||
class InstallCommandTest extends TestCase
|
class InstallCommandTest extends TestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var InstallCommand
|
||||||
|
*/
|
||||||
|
protected $command;
|
||||||
/**
|
/**
|
||||||
* @var CommandTester
|
* @var CommandTester
|
||||||
*/
|
*/
|
||||||
@@ -51,50 +57,83 @@ class InstallCommandTest extends TestCase
|
|||||||
$helperSet = $app->getHelperSet();
|
$helperSet = $app->getHelperSet();
|
||||||
$helperSet->set($processHelper->reveal());
|
$helperSet->set($processHelper->reveal());
|
||||||
$app->setHelperSet($helperSet);
|
$app->setHelperSet($helperSet);
|
||||||
$command = new InstallCommand(
|
$this->command = new InstallCommand(
|
||||||
$this->configWriter->reveal(),
|
$this->configWriter->reveal(),
|
||||||
$this->filesystem->reveal(),
|
$this->filesystem->reveal(),
|
||||||
$configCustomizers->reveal()
|
$configCustomizers->reveal()
|
||||||
);
|
);
|
||||||
$app->add($command);
|
$app->add($this->command);
|
||||||
|
|
||||||
$questionHelper = $command->getHelper('question');
|
$this->commandTester = new CommandTester($this->command);
|
||||||
// $questionHelper->setInputStream($this->createInputStream());
|
|
||||||
$this->commandTester = new CommandTester($command);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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;
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function inputIsProperlyParsed()
|
public function generatedConfigIsProperlyPersisted()
|
||||||
{
|
{
|
||||||
$this->configWriter->toFile(Argument::any(), Argument::type('array'), false)->shouldBeCalledTimes(1);
|
$this->configWriter->toFile(Argument::any(), Argument::type('array'), false)->shouldBeCalledTimes(1);
|
||||||
|
$this->commandTester->execute([]);
|
||||||
|
}
|
||||||
|
|
||||||
$this->commandTester->execute([
|
/**
|
||||||
'command' => 'shlink:install',
|
* @test
|
||||||
|
*/
|
||||||
|
public function cachedConfigIsDeletedIfExists()
|
||||||
|
{
|
||||||
|
/** @var MethodProphecy $appConfigExists */
|
||||||
|
$appConfigExists = $this->filesystem->exists('data/cache/app_config.php')->willReturn(true);
|
||||||
|
/** @var MethodProphecy $appConfigRemove */
|
||||||
|
$appConfigRemove = $this->filesystem->remove('data/cache/app_config.php')->willReturn(null);
|
||||||
|
|
||||||
|
$this->commandTester->execute([]);
|
||||||
|
|
||||||
|
$appConfigExists->shouldHaveBeenCalledTimes(1);
|
||||||
|
$appConfigRemove->shouldHaveBeenCalledTimes(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function exceptionWhileDeletingCachedConfigCancelsProcess()
|
||||||
|
{
|
||||||
|
/** @var MethodProphecy $appConfigExists */
|
||||||
|
$appConfigExists = $this->filesystem->exists('data/cache/app_config.php')->willReturn(true);
|
||||||
|
/** @var MethodProphecy $appConfigRemove */
|
||||||
|
$appConfigRemove = $this->filesystem->remove('data/cache/app_config.php')->willThrow(IOException::class);
|
||||||
|
/** @var MethodProphecy $configToFile */
|
||||||
|
$configToFile = $this->configWriter->toFile(Argument::cetera())->willReturn(true);
|
||||||
|
|
||||||
|
$this->commandTester->execute([]);
|
||||||
|
|
||||||
|
$appConfigExists->shouldHaveBeenCalledTimes(1);
|
||||||
|
$appConfigRemove->shouldHaveBeenCalledTimes(1);
|
||||||
|
$configToFile->shouldNotHaveBeenCalled();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function whenCommandIsUpdatePreviousConfigCanBeImported()
|
||||||
|
{
|
||||||
|
$ref = new \ReflectionObject($this->command);
|
||||||
|
$prop = $ref->getProperty('isUpdate');
|
||||||
|
$prop->setAccessible(true);
|
||||||
|
$prop->setValue($this->command, true);
|
||||||
|
|
||||||
|
/** @var MethodProphecy $importedConfigExists */
|
||||||
|
$importedConfigExists = $this->filesystem->exists(
|
||||||
|
__DIR__ . '/../../../test-resources/' . InstallCommand::GENERATED_CONFIG_PATH
|
||||||
|
)->willReturn(true);
|
||||||
|
|
||||||
|
$this->commandTester->setInputs([
|
||||||
|
'',
|
||||||
|
'/foo/bar/wrong_previous_shlink',
|
||||||
|
'',
|
||||||
|
__DIR__ . '/../../../test-resources',
|
||||||
]);
|
]);
|
||||||
|
$this->commandTester->execute([]);
|
||||||
|
|
||||||
|
$importedConfigExists->shouldHaveBeenCalled();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user