diff --git a/app/code/Magento/Config/Setup/ConfigOptionsList.php b/app/code/Magento/Config/Setup/ConfigOptionsList.php index c410eeae615e5..59ac897a8edea 100644 --- a/app/code/Magento/Config/Setup/ConfigOptionsList.php +++ b/app/code/Magento/Config/Setup/ConfigOptionsList.php @@ -8,11 +8,10 @@ namespace Magento\Config\Setup; use Magento\Framework\App\DeploymentConfig; -use Magento\Framework\Config\Data\ConfigData; use Magento\Framework\Config\Data\ConfigDataFactory; use Magento\Framework\Config\File\ConfigFilePool; use Magento\Framework\Setup\ConfigOptionsListInterface; -use Magento\Framework\Setup\Option\SelectConfigOption; +use Magento\Framework\Setup\Option\BooleanConfigOption; /** * Deployment configuration options required for the Config module. @@ -23,17 +22,14 @@ class ConfigOptionsList implements ConfigOptionsListInterface * Input key for the debug_logging option. */ const INPUT_KEY_DEBUG_LOGGING = 'enable-debug-logging'; - /** * Path to the debug_logging value in the deployment config. */ const CONFIG_PATH_DEBUG_LOGGING = 'dev/debug/debug_logging'; - /** * Input key for the syslog_logging option. */ const INPUT_KEY_SYSLOG_LOGGING = 'enable-syslog-logging'; - /** * Path to the syslog_logging value in the deployment config. */ @@ -58,17 +54,14 @@ public function __construct(ConfigDataFactory $configDataFactory) public function getOptions() { return [ - new SelectConfigOption( + new BooleanConfigOption( self::INPUT_KEY_DEBUG_LOGGING, - SelectConfigOption::FRONTEND_WIZARD_RADIO, - [true, false, 1, 0], self::CONFIG_PATH_DEBUG_LOGGING, - 'Enable debug logging' + 'Enable debug logging', + null ), - new SelectConfigOption( + new BooleanConfigOption( self::INPUT_KEY_SYSLOG_LOGGING, - SelectConfigOption::FRONTEND_WIZARD_RADIO, - [true, false, 1, 0], self::CONFIG_PATH_SYSLOG_LOGGING, 'Enable syslog logging' ), @@ -87,49 +80,40 @@ public function createConfig(array $options, DeploymentConfig $deploymentConfig) $config = []; foreach ($deploymentOption as $inputKey => $configPath) { - $configValue = $this->processBooleanConfigValue( - $inputKey, + $configData = $this->configDataFactory->create(ConfigFilePool::APP_ENV); + $config[] = $configData; + if (!isset($options[$inputKey])) { + continue; + } + $configData->set( $configPath, - $options + $this->boolVal($options[$inputKey]) ); - if ($configValue) { - $config[] = $configValue; - } } return $config; } /** - * Provide config value from input. - * - * @param string $inputKey - * @param string $configPath - * @param array $options - * @return ConfigData|null + * @inheritdoc */ - private function processBooleanConfigValue(string $inputKey, string $configPath, array &$options): ?ConfigData + public function validate(array $options, DeploymentConfig $deploymentConfig) { - $configData = null; - if (isset($options[$inputKey])) { - $configData = $this->configDataFactory->create(ConfigFilePool::APP_ENV); - if ($options[$inputKey] === 'true' - || $options[$inputKey] === '1') { - $value = 1; - } else { - $value = 0; - } - $configData->set($configPath, $value); - } - - return $configData; + return []; } /** - * @inheritdoc + * Convert any valid input option to a boolean + * + * @param mixed $option + * + * @return int|null */ - public function validate(array $options, DeploymentConfig $deploymentConfig) + private function boolVal($option): ?int { - return []; + if ($option === '') { + return null; + } + return (int)in_array(strtolower((string)$option), BooleanConfigOption::OPTIONS_POSITIVE); } } diff --git a/app/code/Magento/Developer/Model/Logger/Handler/Debug.php b/app/code/Magento/Developer/Model/Logger/Handler/Debug.php index fc659c773c0af..71a6e37d46c54 100644 --- a/app/code/Magento/Developer/Model/Logger/Handler/Debug.php +++ b/app/code/Magento/Developer/Model/Logger/Handler/Debug.php @@ -6,10 +6,9 @@ namespace Magento\Developer\Model\Logger\Handler; use Magento\Config\Setup\ConfigOptionsList; -use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\DeploymentConfig; use Magento\Framework\App\State; use Magento\Framework\Filesystem\DriverInterface; -use Magento\Framework\App\DeploymentConfig; /** * Enable/disable debug logging based on the store config setting diff --git a/app/code/Magento/Developer/Model/Logger/Handler/Syslog.php b/app/code/Magento/Developer/Model/Logger/Handler/Syslog.php index c6ee70fb9ce40..6f66fceec8706 100644 --- a/app/code/Magento/Developer/Model/Logger/Handler/Syslog.php +++ b/app/code/Magento/Developer/Model/Logger/Handler/Syslog.php @@ -8,7 +8,6 @@ namespace Magento\Developer\Model\Logger\Handler; use Magento\Config\Setup\ConfigOptionsList; -use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\DeploymentConfig; /** diff --git a/app/code/Magento/MessageQueue/Setup/ConfigOptionsList.php b/app/code/Magento/MessageQueue/Setup/ConfigOptionsList.php index b23dc7fbbf532..79a4868c470c6 100644 --- a/app/code/Magento/MessageQueue/Setup/ConfigOptionsList.php +++ b/app/code/Magento/MessageQueue/Setup/ConfigOptionsList.php @@ -7,11 +7,11 @@ namespace Magento\MessageQueue\Setup; -use Magento\Framework\Setup\ConfigOptionsListInterface; -use Magento\Framework\Setup\Option\SelectConfigOption; use Magento\Framework\App\DeploymentConfig; use Magento\Framework\Config\Data\ConfigData; use Magento\Framework\Config\File\ConfigFilePool; +use Magento\Framework\Setup\ConfigOptionsListInterface; +use Magento\Framework\Setup\Option\BooleanConfigOption; /** * Deployment configuration consumers options needed for Setup application @@ -21,37 +21,26 @@ class ConfigOptionsList implements ConfigOptionsListInterface /** * Input key for the option */ - const INPUT_KEY_QUEUE_CONSUMERS_WAIT_FOR_MESSAGES ='consumers-wait-for-messages'; - + const INPUT_KEY_QUEUE_CONSUMERS_WAIT_FOR_MESSAGES = 'consumers-wait-for-messages'; /** * Path to the value in the deployment config */ const CONFIG_PATH_QUEUE_CONSUMERS_WAIT_FOR_MESSAGES = 'queue/consumers_wait_for_messages'; - /** * Default value */ const DEFAULT_CONSUMERS_WAIT_FOR_MESSAGES = 1; - /** - * The available configuration values - * - * @var array - */ - private $selectOptions = [0, 1]; - /** * @inheritdoc */ - public function getOptions() + public function getOptions(): array { return [ - new SelectConfigOption( + new BooleanConfigOption( self::INPUT_KEY_QUEUE_CONSUMERS_WAIT_FOR_MESSAGES, - SelectConfigOption::FRONTEND_WIZARD_SELECT, - $this->selectOptions, self::CONFIG_PATH_QUEUE_CONSUMERS_WAIT_FOR_MESSAGES, - 'Should consumers wait for a message from the queue? 1 - Yes, 0 - No', + 'Should consumers wait for a message from the queue?', self::DEFAULT_CONSUMERS_WAIT_FOR_MESSAGES ), ]; @@ -61,48 +50,45 @@ public function getOptions() * @inheritdoc * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function createConfig(array $data, DeploymentConfig $deploymentConfig) + public function createConfig(array $data, DeploymentConfig $deploymentConfig): array { - $configData = new ConfigData(ConfigFilePool::APP_ENV); + $deploymentOption = [ + self::INPUT_KEY_QUEUE_CONSUMERS_WAIT_FOR_MESSAGES => self::CONFIG_PATH_QUEUE_CONSUMERS_WAIT_FOR_MESSAGES, + ]; - if (!$this->isDataEmpty($data, self::INPUT_KEY_QUEUE_CONSUMERS_WAIT_FOR_MESSAGES)) { + $config = []; + foreach ($deploymentOption as $inputKey => $configPath) { + $configData = new ConfigData(ConfigFilePool::APP_ENV); + $config[] = $configData; + if (!isset($data[$inputKey])) { + continue; + } $configData->set( - self::CONFIG_PATH_QUEUE_CONSUMERS_WAIT_FOR_MESSAGES, - (int)$data[self::INPUT_KEY_QUEUE_CONSUMERS_WAIT_FOR_MESSAGES] + $configPath, + $this->boolVal($data[$inputKey]) ); } - return [$configData]; + return $config; } /** * @inheritdoc */ - public function validate(array $options, DeploymentConfig $deploymentConfig) + public function validate(array $options, DeploymentConfig $deploymentConfig): array { - $errors = []; - - if (!$this->isDataEmpty($options, self::INPUT_KEY_QUEUE_CONSUMERS_WAIT_FOR_MESSAGES) - && !in_array($options[self::INPUT_KEY_QUEUE_CONSUMERS_WAIT_FOR_MESSAGES], $this->selectOptions)) { - $errors[] = 'You can use only 1 or 0 for ' . self::INPUT_KEY_QUEUE_CONSUMERS_WAIT_FOR_MESSAGES . ' option'; - } - - return $errors; + return []; } /** - * Check if data ($data) with key ($key) is empty + * Convert any valid input option to a boolean + * + * @param mixed $option * - * @param array $data - * @param string $key - * @return bool + * @return int|null */ - private function isDataEmpty(array $data, $key) + private function boolVal($option): ?int { - if (isset($data[$key]) && $data[$key] !== '') { - return false; - } - - return true; + return (int)in_array(strtolower((string)$option), BooleanConfigOption::OPTIONS_POSITIVE); } } diff --git a/dev/tests/integration/testsuite/Magento/Developer/Model/Logger/Handler/DebugTest.php b/dev/tests/integration/testsuite/Magento/Developer/Model/Logger/Handler/DebugTest.php index 6190742cced14..531b71ba67369 100644 --- a/dev/tests/integration/testsuite/Magento/Developer/Model/Logger/Handler/DebugTest.php +++ b/dev/tests/integration/testsuite/Magento/Developer/Model/Logger/Handler/DebugTest.php @@ -125,7 +125,7 @@ public function testDebugInProductionMode() $this->removeDebugLog(); $this->logger->debug($message); - $this->assertFileNotExists($this->getDebuggerLogPath()); + $this->assertFileDoesNotExist($this->getDebuggerLogPath()); $this->assertNull($this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_DEBUG_LOGGING)); $this->checkCommonFlow($message); @@ -235,6 +235,6 @@ private function checkCommonFlow(string $message) $this->enableDebugging(false); $this->removeDebugLog(); $this->logger->debug($message); - $this->assertFileNotExists($this->getDebuggerLogPath()); + $this->assertFileDoesNotExist($this->getDebuggerLogPath()); } } diff --git a/lib/internal/Magento/Framework/Filesystem/Driver/File.php b/lib/internal/Magento/Framework/Filesystem/Driver/File.php index 1affad5521372..e58fa9e07656b 100644 --- a/lib/internal/Magento/Framework/Filesystem/Driver/File.php +++ b/lib/internal/Magento/Framework/Filesystem/Driver/File.php @@ -257,7 +257,7 @@ public function readDirectory($path) $flags = \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::UNIX_PATHS | \RecursiveDirectoryIterator::FOLLOW_SYMLINKS; - + $iterator = new \FilesystemIterator($path, $flags); $result = []; /** @var \FilesystemIterator $file */ @@ -952,7 +952,7 @@ public function readDirectoryRecursively($path = null) $flags = \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::UNIX_PATHS | \RecursiveDirectoryIterator::FOLLOW_SYMLINKS; - + try { $iterator = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator($path, $flags), diff --git a/lib/internal/Magento/Framework/Setup/Option/BooleanConfigOption.php b/lib/internal/Magento/Framework/Setup/Option/BooleanConfigOption.php new file mode 100644 index 0000000000000..6198f211d3e1d --- /dev/null +++ b/lib/internal/Magento/Framework/Setup/Option/BooleanConfigOption.php @@ -0,0 +1,76 @@ +getName()}' is not supported: '{$data}'"); + } + parent::validate($data); + } +} diff --git a/setup/src/Magento/Setup/Model/ConfigGenerator.php b/setup/src/Magento/Setup/Model/ConfigGenerator.php index 09d15489812e2..57f462c747ee4 100644 --- a/setup/src/Magento/Setup/Model/ConfigGenerator.php +++ b/setup/src/Magento/Setup/Model/ConfigGenerator.php @@ -140,7 +140,7 @@ public function createSessionConfig(array $data) * Creates definitions config data * * @param array $data - * @return ConfigData + * @return ConfigData|null * @deprecated 2.2.0 * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsList.php b/setup/src/Magento/Setup/Model/ConfigOptionsList.php index a8d0a8591f539..44457f3e3fac2 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsList.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsList.php @@ -11,6 +11,7 @@ use Magento\Framework\Config\ConfigOptionsListConstants; use Magento\Framework\Encryption\KeyValidator; use Magento\Framework\Setup\ConfigOptionsListInterface; +use Magento\Framework\Setup\Option\BooleanConfigOption; use Magento\Framework\Setup\Option\FlagConfigOption; use Magento\Framework\Setup\Option\TextConfigOption; use Magento\Setup\Model\ConfigOptionsList\DriverOptions; @@ -197,7 +198,7 @@ public function getOptions() 'Full path of server certificate file in order to establish db connection through SSL', '' ), - new FlagConfigOption( + new BooleanConfigOption( ConfigOptionsListConstants::INPUT_KEY_DB_SSL_VERIFY, ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT_DRIVER_OPTIONS . '/' . ConfigOptionsListConstants::KEY_MYSQL_SSL_VERIFY, diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsList/Cache.php b/setup/src/Magento/Setup/Model/ConfigOptionsList/Cache.php index 72699c4acb0bd..5c6fec18e7a31 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsList/Cache.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsList/Cache.php @@ -7,11 +7,11 @@ namespace Magento\Setup\Model\ConfigOptionsList; -use Magento\Framework\Setup\ConfigOptionsListInterface; use Magento\Framework\App\DeploymentConfig; use Magento\Framework\Config\Data\ConfigData; use Magento\Framework\Config\File\ConfigFilePool; -use Magento\Framework\Setup\Option\FlagConfigOption; +use Magento\Framework\Setup\ConfigOptionsListInterface; +use Magento\Framework\Setup\Option\BooleanConfigOption; use Magento\Framework\Setup\Option\SelectConfigOption; use Magento\Framework\Setup\Option\TextConfigOption; use Magento\Setup\Validator\RedisConnectionValidator; @@ -74,7 +74,6 @@ class Cache implements ConfigOptionsListInterface self::INPUT_KEY_CACHE_BACKEND_REDIS_PASSWORD => self::CONFIG_PATH_CACHE_BACKEND_PASSWORD, self::INPUT_KEY_CACHE_BACKEND_REDIS_COMPRESS_DATA => self::CONFIG_PATH_CACHE_BACKEND_COMPRESS_DATA, self::INPUT_KEY_CACHE_BACKEND_REDIS_COMPRESSION_LIB => self::CONFIG_PATH_CACHE_BACKEND_COMPRESSION_LIB, - self::INPUT_KEY_CACHE_ALLOW_PARALLEL_CACHE_GENERATION => self::CONFIG_PATH_ALLOW_PARALLEL_CACHE_GENERATION, ]; /** @@ -95,7 +94,7 @@ public function __construct(RedisConnectionValidator $redisValidator) /** * @inheritdoc */ - public function getOptions() + public function getOptions(): array { return [ new SelectConfigOption( @@ -147,7 +146,7 @@ public function getOptions() self::CONFIG_PATH_CACHE_ID_PREFIX, 'ID prefix for cache keys' ), - new FlagConfigOption( + new BooleanConfigOption( self::INPUT_KEY_CACHE_ALLOW_PARALLEL_CACHE_GENERATION, self::CONFIG_PATH_ALLOW_PARALLEL_CACHE_GENERATION, 'Allow generate cache in non-blocking way' @@ -158,7 +157,7 @@ public function getOptions() /** * @inheritdoc */ - public function createConfig(array $options, DeploymentConfig $deploymentConfig) + public function createConfig(array $options, DeploymentConfig $deploymentConfig): ConfigData { $configData = new ConfigData(ConfigFilePool::APP_ENV); if (isset($options[self::INPUT_KEY_CACHE_ID_PREFIX])) { @@ -176,6 +175,13 @@ public function createConfig(array $options, DeploymentConfig $deploymentConfig) } } + if (isset($options[self::INPUT_KEY_CACHE_ALLOW_PARALLEL_CACHE_GENERATION])) { + $configData->set( + self::CONFIG_PATH_ALLOW_PARALLEL_CACHE_GENERATION, + $this->boolVal($options[self::INPUT_KEY_CACHE_ALLOW_PARALLEL_CACHE_GENERATION]) + ); + } + foreach ($this->inputKeyToConfigPathMap as $inputKey => $configPath) { if (isset($options[$inputKey])) { $configData->set($configPath, $options[$inputKey]); @@ -187,7 +193,7 @@ public function createConfig(array $options, DeploymentConfig $deploymentConfig) /** * @inheritdoc */ - public function validate(array $options, DeploymentConfig $deploymentConfig) + public function validate(array $options, DeploymentConfig $deploymentConfig): array { $errors = []; @@ -220,7 +226,7 @@ public function validate(array $options, DeploymentConfig $deploymentConfig) * @param DeploymentConfig $deploymentConfig * @return bool */ - private function validateRedisConfig(array $options, DeploymentConfig $deploymentConfig) + private function validateRedisConfig(array $options, DeploymentConfig $deploymentConfig): bool { $config = []; @@ -262,7 +268,7 @@ private function validateRedisConfig(array $options, DeploymentConfig $deploymen * @param ConfigData $configData * @return ConfigData */ - private function setDefaultRedisConfig(DeploymentConfig $deploymentConfig, ConfigData $configData) + private function setDefaultRedisConfig(DeploymentConfig $deploymentConfig, ConfigData $configData): ConfigData { foreach ($this->inputKeyToConfigPathMap as $inputKey => $configPath) { $configData->set($configPath, $deploymentConfig->get($configPath, $this->getDefaultConfigValue($inputKey))); @@ -277,7 +283,7 @@ private function setDefaultRedisConfig(DeploymentConfig $deploymentConfig, Confi * @param string $inputKey * @return string */ - private function getDefaultConfigValue($inputKey) + private function getDefaultConfigValue($inputKey): string { if (isset($this->defaultConfigValues[$inputKey])) { return $this->defaultConfigValues[$inputKey]; @@ -293,6 +299,19 @@ private function getDefaultConfigValue($inputKey) */ private function generateCachePrefix(): string { + // phpcs:ignore Magento2.Functions.DiscouragedFunction return substr(\hash('sha256', dirname(__DIR__, 6)), 0, 3) . '_'; } + + /** + * Convert any valid input option to a boolean + * + * @param mixed $option + * + * @return bool + */ + private function boolVal($option): bool + { + return in_array(strtolower((string)$option), BooleanConfigOption::OPTIONS_POSITIVE); + } } diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsList/Directory.php b/setup/src/Magento/Setup/Model/ConfigOptionsList/Directory.php index e838dbee33603..623191a90eb3a 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsList/Directory.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsList/Directory.php @@ -8,83 +8,71 @@ namespace Magento\Setup\Model\ConfigOptionsList; use Magento\Framework\App\DeploymentConfig; +use Magento\Framework\Config\ConfigOptionsListConstants; use Magento\Framework\Config\Data\ConfigData; use Magento\Framework\Config\File\ConfigFilePool; use Magento\Framework\Setup\ConfigOptionsListInterface; -use Magento\Framework\Setup\Option\SelectConfigOption; +use Magento\Framework\Setup\Option\BooleanConfigOption; /** - * Deployment configuration options for the folders. + * Deployment configuration options for the document root */ class Directory implements ConfigOptionsListInterface { - /** - * Input key for config command. - */ - private const INPUT_KEY_DOCUMENT_ROOT_IS_PUB = 'document-root-is-pub'; - - /** - * Path in in configuration. - */ - const CONFIG_PATH_DOCUMENT_ROOT_IS_PUB = 'directories/document_root_is_pub'; + public const INPUT_KEY_DOCUMENT_ROOT_IS_PUB = 'document-root-is-pub'; /** - * The available configuration values. - * - * @var array + * @inheritdoc */ - private $selectOptions = [true, false]; + public function getOptions(): array + { + return [ + new BooleanConfigOption( + self::INPUT_KEY_DOCUMENT_ROOT_IS_PUB, + ConfigOptionsListConstants::CONFIG_PATH_DOCUMENT_ROOT_IS_PUB, + "Is the webserver's document root set to ./pub/" + ), + ]; + } /** - * Create config and update document root value according to provided options - * - * @param array $options - * @param DeploymentConfig $deploymentConfig - * @return ConfigData|ConfigData[] - * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @inheritdoc */ - public function createConfig(array $options, DeploymentConfig $deploymentConfig) + public function createConfig(array $options, DeploymentConfig $deploymentConfig): ConfigData { + $deploymentOption = [ + self::INPUT_KEY_DOCUMENT_ROOT_IS_PUB => ConfigOptionsListConstants::CONFIG_PATH_DOCUMENT_ROOT_IS_PUB, + ]; + $configData = new ConfigData(ConfigFilePool::APP_ENV); - if (isset($options[self::INPUT_KEY_DOCUMENT_ROOT_IS_PUB])) { - $configData->set( - self::CONFIG_PATH_DOCUMENT_ROOT_IS_PUB, - \filter_var($options[self::INPUT_KEY_DOCUMENT_ROOT_IS_PUB], FILTER_VALIDATE_BOOLEAN) - ); + + foreach ($deploymentOption as $inputKey => $configPath) { + if (!isset($options[$inputKey])) { + continue; + } + $configData->set($configPath, $this->boolVal($options[$inputKey])); } return $configData; } /** - * Return options from Directory configuration. - * - * @return \Magento\Framework\Setup\Option\AbstractConfigOption[]|SelectConfigOption[] + * @inheritdoc */ - public function getOptions() + public function validate(array $options, DeploymentConfig $deploymentConfig): array { - return [ - new SelectConfigOption( - self::INPUT_KEY_DOCUMENT_ROOT_IS_PUB, - SelectConfigOption::FRONTEND_WIZARD_SELECT, - $this->selectOptions, - self::CONFIG_PATH_DOCUMENT_ROOT_IS_PUB, - 'Flag to show is Pub is on root, can be true or false only', - false - ), - ]; + return []; } /** - * Validate options. + * Convert any valid input option to a boolean + * + * @param mixed $option * - * @param array $options - * @param DeploymentConfig $deploymentConfig - * @return array|string[] - * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @return bool */ - public function validate(array $options, DeploymentConfig $deploymentConfig) + private function boolVal($option): bool { - return []; + return in_array(strtolower((string)$option), BooleanConfigOption::OPTIONS_POSITIVE); } } diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php index 0707f99d67976..07e041bd57b29 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php @@ -8,7 +8,8 @@ namespace Magento\Setup\Test\Unit\Model\ConfigOptionsList; use Magento\Framework\App\DeploymentConfig; -use Magento\Framework\Setup\Option\FlagConfigOption; +use Magento\Framework\Cache\Backend\Redis; +use Magento\Framework\Setup\Option\BooleanConfigOption; use Magento\Framework\Setup\Option\SelectConfigOption; use Magento\Framework\Setup\Option\TextConfigOption; use Magento\Setup\Model\ConfigOptionsList\Cache as CacheConfigOptionsList; @@ -18,7 +19,7 @@ class CacheTest extends TestCase { /** - * @var \Magento\Setup\Model\ConfigOptionsList\Cache + * @var CacheConfigOptionsList */ private $configOptionsList; @@ -46,7 +47,7 @@ protected function setUp(): void /** * testGetOptions */ - public function testGetOptions() + public function testGetOptions(): void { $options = $this->configOptionsList->getOptions(); $this->assertCount(9, $options); @@ -84,14 +85,14 @@ public function testGetOptions() $this->assertEquals('cache-id-prefix', $options[7]->getName()); $this->assertArrayHasKey(8, $options); - $this->assertInstanceOf(FlagConfigOption::class, $options[8]); + $this->assertInstanceOf(BooleanConfigOption::class, $options[8]); $this->assertEquals('allow-parallel-generation', $options[8]->getName()); } /** * testCreateConfigCacheRedis */ - public function testCreateConfigCacheRedis() + public function testCreateConfigCacheRedis(): void { $this->deploymentConfigMock->method('get')->willReturn(''); @@ -99,50 +100,48 @@ public function testCreateConfigCacheRedis() 'cache' => [ 'frontend' => [ 'default' => [ - 'backend' => \Magento\Framework\Cache\Backend\Redis::class, + 'id_prefix' => $this->expectedIdPrefix(), + 'backend' => Redis::class, 'backend_options' => [ 'server' => '', - 'port' => '', 'database' => '', + 'port' => '', 'password' => '', 'compress_data' => '', 'compression_lib' => '', ], - 'id_prefix' => $this->expectedIdPrefix(), ] ], - 'allow_parallel_generation' => '', ] ]; $configData = $this->configOptionsList ->createConfig(['cache-backend' => 'redis'], $this->deploymentConfigMock); - $this->assertEquals($expectedConfigData, $configData->getData()); + $this->assertSame($expectedConfigData, $configData->getData()); } /** * testCreateConfigWithRedisConfig */ - public function testCreateConfigWithRedisConfig() + public function testCreateConfigWithRedisConfig(): void { $expectedConfigData = [ 'cache' => [ 'frontend' => [ 'default' => [ - 'backend' => \Magento\Framework\Cache\Backend\Redis::class, + 'id_prefix' => $this->expectedIdPrefix(), + 'backend' => Redis::class, 'backend_options' => [ 'server' => 'localhost', - 'port' => '1234', 'database' => '5', - 'password' => '', + 'port' => '1234', + 'password' => null, 'compress_data' => '1', 'compression_lib' => 'gzip', ], - 'id_prefix' => $this->expectedIdPrefix(), ] ], - 'allow_parallel_generation' => null, ] ]; @@ -157,13 +156,13 @@ public function testCreateConfigWithRedisConfig() $configData = $this->configOptionsList->createConfig($options, $this->deploymentConfigMock); - $this->assertEquals($expectedConfigData, $configData->getData()); + $this->assertSame($expectedConfigData, $configData->getData()); } /** * testCreateConfigCacheRedis */ - public function testCreateConfigWithFileCache() + public function testCreateConfigWithFileCache(): void { $this->deploymentConfigMock->method('get')->willReturn(''); @@ -179,13 +178,13 @@ public function testCreateConfigWithFileCache() $configData = $this->configOptionsList->createConfig([], $this->deploymentConfigMock); - $this->assertEquals($expectedConfigData, $configData->getData()); + $this->assertSame($expectedConfigData, $configData->getData()); } /** * testCreateConfigCacheRedis */ - public function testCreateConfigWithIdPrefix() + public function testCreateConfigWithIdPrefix(): void { $this->deploymentConfigMock->method('get')->willReturn(''); @@ -205,13 +204,42 @@ public function testCreateConfigWithIdPrefix() $this->deploymentConfigMock ); - $this->assertEquals($expectedConfigData, $configData->getData()); + $this->assertSame($expectedConfigData, $configData->getData()); + } + + /** + * @dataProvider allowParallelGenerationDataProvider + * + * @param string|null $value + * @param bool $expectedValue + */ + public function testCreateConfigWithAllowParallelGeneration(?string $value, bool $expectedValue): void + { + $this->deploymentConfigMock->method('get')->willReturn(''); + + $expectedConfigData = [ + 'cache' => [ + 'frontend' => [ + 'default' => [ + 'id_prefix' => $this->expectedIdPrefix(), + ] + ], + 'allow_parallel_generation' => $expectedValue + ] + ]; + + $configData = $this->configOptionsList->createConfig( + ['allow-parallel-generation' => $value], + $this->deploymentConfigMock + ); + + $this->assertSame($expectedConfigData, $configData->getData()); } /** * testValidateWithValidInput */ - public function testValidateWithValidInput() + public function testValidateWithValidInput(): void { $options = [ 'cache-backend' => 'redis', @@ -230,7 +258,7 @@ public function testValidateWithValidInput() /** * testValidateWithInvalidInput */ - public function testValidateWithInvalidInput() + public function testValidateWithInvalidInput(): void { $invalidCacheOption = 'clay-tablet'; $options = ['cache-backend' => $invalidCacheOption]; @@ -241,6 +269,21 @@ public function testValidateWithInvalidInput() $this->assertEquals("Invalid cache handler 'clay-tablet'", $errors[0]); } + /** + * @return array[] + */ + public function allowParallelGenerationDataProvider(): array + { + return [ + ['0', false], + ['false', false], + ['no', false], + ['1', true], + ['true', true], + ['yes', true], + ]; + } + /** * The default ID prefix, based on installation directory * diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/DirectoryTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/DirectoryTest.php new file mode 100644 index 0000000000000..79c6794ef5bec --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/DirectoryTest.php @@ -0,0 +1,86 @@ + ['document_root_is_pub' => true]]; + + private $expectedDisabled = ['directories' => ['document_root_is_pub' => false]]; + + private $expectedEmpty = []; + + /** + * Tests setup + */ + protected function setUp(): void + { + $this->deploymentConfigMock = $this->createMock(DeploymentConfig::class); + $this->configOptionsList = new DirectoriesConfigOptionsList(); + } + + /** + * testGetOptions + */ + public function testGetOptions(): void + { + $options = $this->configOptionsList->getOptions(); + $this->assertCount(1, $options); + $this->assertArrayHasKey(0, $options); + $this->assertInstanceOf(BooleanConfigOption::class, $options[0]); + $this->assertEquals('document-root-is-pub', $options[0]->getName()); + } + + /** + * @dataProvider configOptionProvider + * + * @param string|null $value + * @param array $config + */ + public function testCreateConfig(?string $value, array $config): void + { + $configData = $this->configOptionsList->createConfig( + [DirectoriesConfigOptionsList::INPUT_KEY_DOCUMENT_ROOT_IS_PUB => $value], + $this->deploymentConfigMock + ); + + $this->assertSame($config, $configData->getData()); + } + + /** + * @return array[] + */ + public function configOptionProvider(): array + { + return [ + ['value' => '0', 'config' => $this->expectedDisabled], + ['value' => 'false', 'config' => $this->expectedDisabled], + ['value' => 'no', 'config' => $this->expectedDisabled], + ['value' => '1', 'config' => $this->expectedEnabled], + ['value' => 'true', 'config' => $this->expectedEnabled], + ['value' => 'yes', 'config' => $this->expectedEnabled], + ['value' => null, 'config' => $this->expectedEmpty], + ]; + } +}