Updated ConfigCustomizer api to expect a SymfonyStyle object instead of a set of input and output

This commit is contained in:
Alejandro Celaya 2017-12-31 17:14:01 +01:00
parent d275316acd
commit 0e2ad0dbca
10 changed files with 29 additions and 43 deletions

View file

@ -123,7 +123,7 @@ class InstallCommand extends Command
] as $pluginName) { ] as $pluginName) {
/** @var Plugin\ConfigCustomizerPluginInterface $configCustomizer */ /** @var Plugin\ConfigCustomizerPluginInterface $configCustomizer */
$configCustomizer = $this->configCustomizers->get($pluginName); $configCustomizer = $this->configCustomizers->get($pluginName);
$configCustomizer->process($input, $output, $config); $configCustomizer->process($this->io, $config);
} }
// Generate config params files // Generate config params files

View file

@ -5,8 +5,6 @@ namespace Shlinkio\Shlink\CLI\Install\Plugin;
use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig; use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig;
use Shlinkio\Shlink\Common\Util\StringUtilsTrait; use Shlinkio\Shlink\Common\Util\StringUtilsTrait;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Console\Style\SymfonyStyle;
class ApplicationConfigCustomizerPlugin extends AbstractConfigCustomizerPlugin class ApplicationConfigCustomizerPlugin extends AbstractConfigCustomizerPlugin
@ -14,14 +12,12 @@ class ApplicationConfigCustomizerPlugin extends AbstractConfigCustomizerPlugin
use StringUtilsTrait; use StringUtilsTrait;
/** /**
* @param InputInterface $input * @param SymfonyStyle $io
* @param OutputInterface $output
* @param CustomizableAppConfig $appConfig * @param CustomizableAppConfig $appConfig
* @return void * @return void
*/ */
public function process(InputInterface $input, OutputInterface $output, CustomizableAppConfig $appConfig) public function process(SymfonyStyle $io, CustomizableAppConfig $appConfig)
{ {
$io = new SymfonyStyle($input, $output);
$io->title('APPLICATION'); $io->title('APPLICATION');
if ($appConfig->hasApp() && $io->confirm('Do you want to keep imported application config?')) { if ($appConfig->hasApp() && $io->confirm('Do you want to keep imported application config?')) {

View file

@ -4,16 +4,14 @@ declare(strict_types=1);
namespace Shlinkio\Shlink\CLI\Install\Plugin; namespace Shlinkio\Shlink\CLI\Install\Plugin;
use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig; use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Console\Output\OutputInterface;
interface ConfigCustomizerPluginInterface interface ConfigCustomizerPluginInterface
{ {
/** /**
* @param InputInterface $input * @param SymfonyStyle $io
* @param OutputInterface $output
* @param CustomizableAppConfig $appConfig * @param CustomizableAppConfig $appConfig
* @return void * @return void
*/ */
public function process(InputInterface $input, OutputInterface $output, CustomizableAppConfig $appConfig); public function process(SymfonyStyle $io, CustomizableAppConfig $appConfig);
} }

View file

@ -4,8 +4,6 @@ declare(strict_types=1);
namespace Shlinkio\Shlink\CLI\Install\Plugin; namespace Shlinkio\Shlink\CLI\Install\Plugin;
use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig; use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Filesystem\Exception\IOException; use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Filesystem;
@ -29,15 +27,13 @@ class DatabaseConfigCustomizerPlugin extends AbstractConfigCustomizerPlugin
} }
/** /**
* @param InputInterface $input * @param SymfonyStyle $io
* @param OutputInterface $output
* @param CustomizableAppConfig $appConfig * @param CustomizableAppConfig $appConfig
* @return void * @return void
* @throws IOException * @throws IOException
*/ */
public function process(InputInterface $input, OutputInterface $output, CustomizableAppConfig $appConfig) public function process(SymfonyStyle $io, CustomizableAppConfig $appConfig)
{ {
$io = new SymfonyStyle($input, $output);
$io->title('DATABASE'); $io->title('DATABASE');
if ($appConfig->hasDatabase() && $io->confirm('Do you want to keep imported database config?')) { if ($appConfig->hasDatabase() && $io->confirm('Do you want to keep imported database config?')) {

View file

@ -4,8 +4,6 @@ declare(strict_types=1);
namespace Shlinkio\Shlink\CLI\Install\Plugin; namespace Shlinkio\Shlink\CLI\Install\Plugin;
use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig; use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Console\Style\SymfonyStyle;
class LanguageConfigCustomizerPlugin extends AbstractConfigCustomizerPlugin class LanguageConfigCustomizerPlugin extends AbstractConfigCustomizerPlugin
@ -13,14 +11,12 @@ class LanguageConfigCustomizerPlugin extends AbstractConfigCustomizerPlugin
const SUPPORTED_LANGUAGES = ['en', 'es']; const SUPPORTED_LANGUAGES = ['en', 'es'];
/** /**
* @param InputInterface $input * @param SymfonyStyle $io
* @param OutputInterface $output
* @param CustomizableAppConfig $appConfig * @param CustomizableAppConfig $appConfig
* @return void * @return void
*/ */
public function process(InputInterface $input, OutputInterface $output, CustomizableAppConfig $appConfig) public function process(SymfonyStyle $io, CustomizableAppConfig $appConfig)
{ {
$io = new SymfonyStyle($input, $output);
$io->title('LANGUAGE'); $io->title('LANGUAGE');
if ($appConfig->hasLanguage() && $io->confirm('Do you want to keep imported language?')) { if ($appConfig->hasLanguage() && $io->confirm('Do you want to keep imported language?')) {

View file

@ -5,21 +5,17 @@ namespace Shlinkio\Shlink\CLI\Install\Plugin;
use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig; use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig;
use Shlinkio\Shlink\Core\Service\UrlShortener; use Shlinkio\Shlink\Core\Service\UrlShortener;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Console\Style\SymfonyStyle;
class UrlShortenerConfigCustomizerPlugin extends AbstractConfigCustomizerPlugin class UrlShortenerConfigCustomizerPlugin extends AbstractConfigCustomizerPlugin
{ {
/** /**
* @param InputInterface $input * @param SymfonyStyle $io
* @param OutputInterface $output
* @param CustomizableAppConfig $appConfig * @param CustomizableAppConfig $appConfig
* @return void * @return void
*/ */
public function process(InputInterface $input, OutputInterface $output, CustomizableAppConfig $appConfig) public function process(SymfonyStyle $io, CustomizableAppConfig $appConfig)
{ {
$io = new SymfonyStyle($input, $output);
$io->title('URL SHORTENER'); $io->title('URL SHORTENER');
if ($appConfig->hasUrlShortener() && $io->confirm('Do you want to keep imported URL shortener config?')) { if ($appConfig->hasUrlShortener() && $io->confirm('Do you want to keep imported URL shortener config?')) {

View file

@ -13,6 +13,7 @@ use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Style\SymfonyStyle;
class ApplicationConfigCustomizerPluginTest extends TestCase class ApplicationConfigCustomizerPluginTest extends TestCase
{ {
@ -40,7 +41,7 @@ class ApplicationConfigCustomizerPluginTest extends TestCase
$askSecret = $this->questionHelper->ask(Argument::cetera())->willReturn('the_secret'); $askSecret = $this->questionHelper->ask(Argument::cetera())->willReturn('the_secret');
$config = new CustomizableAppConfig(); $config = new CustomizableAppConfig();
$this->plugin->process(new ArrayInput([]), new NullOutput(), $config); $this->plugin->process(new SymfonyStyle(new ArrayInput([]), new NullOutput()), $config);
$this->assertTrue($config->hasApp()); $this->assertTrue($config->hasApp());
$this->assertEquals([ $this->assertEquals([
@ -64,7 +65,7 @@ class ApplicationConfigCustomizerPluginTest extends TestCase
'SECRET' => 'foo', 'SECRET' => 'foo',
]); ]);
$this->plugin->process(new ArrayInput([]), new NullOutput(), $config); $this->plugin->process(new SymfonyStyle(new ArrayInput([]), new NullOutput()), $config);
$this->assertEquals([ $this->assertEquals([
'SECRET' => 'the_new_secret', 'SECRET' => 'the_new_secret',
@ -85,7 +86,7 @@ class ApplicationConfigCustomizerPluginTest extends TestCase
'SECRET' => 'foo', 'SECRET' => 'foo',
]); ]);
$this->plugin->process(new ArrayInput([]), new NullOutput(), $config); $this->plugin->process(new SymfonyStyle(new ArrayInput([]), new NullOutput()), $config);
$this->assertEquals([ $this->assertEquals([
'SECRET' => 'foo', 'SECRET' => 'foo',

View file

@ -13,6 +13,7 @@ use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Filesystem;
class DatabaseConfigCustomizerPluginTest extends TestCase class DatabaseConfigCustomizerPluginTest extends TestCase
@ -50,7 +51,7 @@ class DatabaseConfigCustomizerPluginTest extends TestCase
$askSecret = $this->questionHelper->ask(Argument::cetera())->willReturn('MySQL'); $askSecret = $this->questionHelper->ask(Argument::cetera())->willReturn('MySQL');
$config = new CustomizableAppConfig(); $config = new CustomizableAppConfig();
$this->plugin->process(new ArrayInput([]), new NullOutput(), $config); $this->plugin->process(new SymfonyStyle(new ArrayInput([]), new NullOutput()), $config);
$this->assertTrue($config->hasDatabase()); $this->assertTrue($config->hasDatabase());
$this->assertEquals([ $this->assertEquals([
@ -84,7 +85,7 @@ class DatabaseConfigCustomizerPluginTest extends TestCase
'PORT' => 'MySQL', 'PORT' => 'MySQL',
]); ]);
$this->plugin->process(new ArrayInput([]), new NullOutput(), $config); $this->plugin->process(new SymfonyStyle(new ArrayInput([]), new NullOutput()), $config);
$this->assertEquals([ $this->assertEquals([
'DRIVER' => 'pdo_mysql', 'DRIVER' => 'pdo_mysql',
@ -115,7 +116,7 @@ class DatabaseConfigCustomizerPluginTest extends TestCase
'PORT' => 'MySQL', 'PORT' => 'MySQL',
]); ]);
$this->plugin->process(new ArrayInput([]), new NullOutput(), $config); $this->plugin->process(new SymfonyStyle(new ArrayInput([]), new NullOutput()), $config);
$this->assertEquals([ $this->assertEquals([
'DRIVER' => 'pdo_pgsql', 'DRIVER' => 'pdo_pgsql',
@ -143,7 +144,7 @@ class DatabaseConfigCustomizerPluginTest extends TestCase
'DRIVER' => 'pdo_sqlite', 'DRIVER' => 'pdo_sqlite',
]); ]);
$this->plugin->process(new ArrayInput([]), new NullOutput(), $config); $this->plugin->process(new SymfonyStyle(new ArrayInput([]), new NullOutput()), $config);
$this->assertEquals([ $this->assertEquals([
'DRIVER' => 'pdo_sqlite', 'DRIVER' => 'pdo_sqlite',

View file

@ -13,6 +13,7 @@ use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Style\SymfonyStyle;
class LanguageConfigCustomizerPluginTest extends TestCase class LanguageConfigCustomizerPluginTest extends TestCase
{ {
@ -40,7 +41,7 @@ class LanguageConfigCustomizerPluginTest extends TestCase
$askSecret = $this->questionHelper->ask(Argument::cetera())->willReturn('en'); $askSecret = $this->questionHelper->ask(Argument::cetera())->willReturn('en');
$config = new CustomizableAppConfig(); $config = new CustomizableAppConfig();
$this->plugin->process(new ArrayInput([]), new NullOutput(), $config); $this->plugin->process(new SymfonyStyle(new ArrayInput([]), new NullOutput()), $config);
$this->assertTrue($config->hasLanguage()); $this->assertTrue($config->hasLanguage());
$this->assertEquals([ $this->assertEquals([
@ -66,7 +67,7 @@ class LanguageConfigCustomizerPluginTest extends TestCase
'CLI' => 'en', 'CLI' => 'en',
]); ]);
$this->plugin->process(new ArrayInput([]), new NullOutput(), $config); $this->plugin->process(new SymfonyStyle(new ArrayInput([]), new NullOutput()), $config);
$this->assertEquals([ $this->assertEquals([
'DEFAULT' => 'es', 'DEFAULT' => 'es',
@ -89,7 +90,7 @@ class LanguageConfigCustomizerPluginTest extends TestCase
'CLI' => 'es', 'CLI' => 'es',
]); ]);
$this->plugin->process(new ArrayInput([]), new NullOutput(), $config); $this->plugin->process(new SymfonyStyle(new ArrayInput([]), new NullOutput()), $config);
$this->assertEquals([ $this->assertEquals([
'DEFAULT' => 'es', 'DEFAULT' => 'es',

View file

@ -13,6 +13,7 @@ use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Style\SymfonyStyle;
class UrlShortenerConfigCustomizerPluginTest extends TestCase class UrlShortenerConfigCustomizerPluginTest extends TestCase
{ {
@ -40,7 +41,7 @@ class UrlShortenerConfigCustomizerPluginTest extends TestCase
$askSecret = $this->questionHelper->ask(Argument::cetera())->willReturn('something'); $askSecret = $this->questionHelper->ask(Argument::cetera())->willReturn('something');
$config = new CustomizableAppConfig(); $config = new CustomizableAppConfig();
$this->plugin->process(new ArrayInput([]), new NullOutput(), $config); $this->plugin->process(new SymfonyStyle(new ArrayInput([]), new NullOutput()), $config);
$this->assertTrue($config->hasUrlShortener()); $this->assertTrue($config->hasUrlShortener());
$this->assertEquals([ $this->assertEquals([
@ -70,7 +71,7 @@ class UrlShortenerConfigCustomizerPluginTest extends TestCase
'VALIDATE_URL' => 'bar', 'VALIDATE_URL' => 'bar',
]); ]);
$this->plugin->process(new ArrayInput([]), new NullOutput(), $config); $this->plugin->process(new SymfonyStyle(new ArrayInput([]), new NullOutput()), $config);
$this->assertEquals([ $this->assertEquals([
'SCHEMA' => 'foo', 'SCHEMA' => 'foo',
@ -97,7 +98,7 @@ class UrlShortenerConfigCustomizerPluginTest extends TestCase
'VALIDATE_URL' => 'foo', 'VALIDATE_URL' => 'foo',
]); ]);
$this->plugin->process(new ArrayInput([]), new NullOutput(), $config); $this->plugin->process(new SymfonyStyle(new ArrayInput([]), new NullOutput()), $config);
$this->assertEquals([ $this->assertEquals([
'SCHEMA' => 'foo', 'SCHEMA' => 'foo',