From f1621732f3ae363ded3b1b74c7c3dcdd48c14ee4 Mon Sep 17 00:00:00 2001 From: Matthew Wells Date: Thu, 4 Feb 2021 09:45:37 +0200 Subject: [PATCH 1/4] Implement command loader --- .../Command/MaintenanceAllowIpsCommand.php | 3 +- .../Command/MaintenanceDisableCommand.php | 4 +- .../Command/MaintenanceEnableCommand.php | 4 +- .../Command/MaintenanceStatusCommand.php | 4 +- .../Test/Integrity/Library/DependencyTest.php | 2 +- .../Console/CommandLoader/AggregateTest.php | 119 ++++++++++++++++++ .../Test/Unit/Console/CommandLoaderTest.php | 114 +++++++++++++++++ .../Magento/Framework/Console/Cli.php | 29 ++++- .../Framework/Console/CommandLoader.php | 77 ++++++++++++ .../Console/CommandLoader/Aggregate.php | 78 ++++++++++++ .../Command/AdminUserCreateCommand.php | 3 +- .../Setup/Console/Command/BackupCommand.php | 3 +- .../Console/Command/ConfigSetCommand.php | 3 +- .../Console/Command/DbDataUpgradeCommand.php | 3 +- .../Command/DbSchemaUpgradeCommand.php | 3 +- .../Setup/Console/Command/DbStatusCommand.php | 3 +- .../DependenciesShowFrameworkCommand.php | 3 +- ...DependenciesShowModulesCircularCommand.php | 4 +- .../DependenciesShowModulesCommand.php | 4 +- .../Command/DeployStaticContentCommand.php | 3 +- .../Command/GenerateFixturesCommand.php | 4 +- .../Command/I18nCollectPhrasesCommand.php | 3 +- .../Setup/Console/Command/I18nPackCommand.php | 3 +- .../Console/Command/InfoAdminUriCommand.php | 3 +- .../Command/InfoBackupsListCommand.php | 3 +- .../Command/InfoCurrencyListCommand.php | 3 +- .../Command/InfoLanguageListCommand.php | 3 +- .../Command/InfoTimezoneListCommand.php | 3 +- .../Setup/Console/Command/InstallCommand.php | 4 +- .../InstallStoreConfigurationCommand.php | 3 +- .../Command/ModuleConfigStatusCommand.php | 3 +- .../Console/Command/ModuleDisableCommand.php | 4 +- .../Console/Command/ModuleEnableCommand.php | 4 +- .../Console/Command/ModuleStatusCommand.php | 3 +- .../Command/ModuleUninstallCommand.php | 3 +- .../Setup/Console/Command/RollbackCommand.php | 3 +- .../Console/Command/UninstallCommand.php | 3 +- .../Setup/Console/Command/UpgradeCommand.php | 4 +- .../src/Magento/Setup/Console/CommandList.php | 97 -------------- .../Magento/Setup/Console/CommandLoader.php | 113 +++++++++++++++++ .../Test/Unit/Console/CommandListTest.php | 40 ------ .../Test/Unit/Console/CommandLoaderTest.php | 45 +++++++ 42 files changed, 644 insertions(+), 176 deletions(-) create mode 100644 lib/internal/Magento/Framework/App/Test/Unit/Console/CommandLoader/AggregateTest.php create mode 100644 lib/internal/Magento/Framework/App/Test/Unit/Console/CommandLoaderTest.php create mode 100644 lib/internal/Magento/Framework/Console/CommandLoader.php create mode 100644 lib/internal/Magento/Framework/Console/CommandLoader/Aggregate.php delete mode 100644 setup/src/Magento/Setup/Console/CommandList.php create mode 100644 setup/src/Magento/Setup/Console/CommandLoader.php delete mode 100644 setup/src/Magento/Setup/Test/Unit/Console/CommandListTest.php create mode 100644 setup/src/Magento/Setup/Test/Unit/Console/CommandLoaderTest.php diff --git a/app/code/Magento/Backend/Console/Command/MaintenanceAllowIpsCommand.php b/app/code/Magento/Backend/Console/Command/MaintenanceAllowIpsCommand.php index 230c6a6814ebc..86c5e59ba91ee 100644 --- a/app/code/Magento/Backend/Console/Command/MaintenanceAllowIpsCommand.php +++ b/app/code/Magento/Backend/Console/Command/MaintenanceAllowIpsCommand.php @@ -25,6 +25,7 @@ class MaintenanceAllowIpsCommand extends AbstractSetupCommand const INPUT_KEY_IP = 'ip'; const INPUT_KEY_NONE = 'none'; const INPUT_KEY_ADD = 'add'; + const NAME = 'maintenance:allow-ips'; /** * @var MaintenanceMode @@ -76,7 +77,7 @@ protected function configure(): void 'Add the IP address to existing list' ), ]; - $this->setName('maintenance:allow-ips') + $this->setName(self::NAME) ->setDescription('Sets maintenance mode exempt IPs') ->setDefinition(array_merge($arguments, $options)); diff --git a/app/code/Magento/Backend/Console/Command/MaintenanceDisableCommand.php b/app/code/Magento/Backend/Console/Command/MaintenanceDisableCommand.php index 5108866fbe65c..34b6c2e9c9e90 100644 --- a/app/code/Magento/Backend/Console/Command/MaintenanceDisableCommand.php +++ b/app/code/Magento/Backend/Console/Command/MaintenanceDisableCommand.php @@ -10,6 +10,8 @@ */ class MaintenanceDisableCommand extends AbstractMaintenanceCommand { + const NAME = 'maintenance:disable'; + /** * Initialization of the command * @@ -17,7 +19,7 @@ class MaintenanceDisableCommand extends AbstractMaintenanceCommand */ protected function configure() { - $this->setName('maintenance:disable')->setDescription('Disables maintenance mode'); + $this->setName(self::NAME)->setDescription('Disables maintenance mode'); parent::configure(); } diff --git a/app/code/Magento/Backend/Console/Command/MaintenanceEnableCommand.php b/app/code/Magento/Backend/Console/Command/MaintenanceEnableCommand.php index 7e5e034483d20..ca8c33f0c31fc 100644 --- a/app/code/Magento/Backend/Console/Command/MaintenanceEnableCommand.php +++ b/app/code/Magento/Backend/Console/Command/MaintenanceEnableCommand.php @@ -10,6 +10,8 @@ */ class MaintenanceEnableCommand extends AbstractMaintenanceCommand { + const NAME = 'maintenance:enable'; + /** * Initialization of the command * @@ -17,7 +19,7 @@ class MaintenanceEnableCommand extends AbstractMaintenanceCommand */ protected function configure(): void { - $this->setName('maintenance:enable')->setDescription('Enables maintenance mode'); + $this->setName(self::NAME)->setDescription('Enables maintenance mode'); parent::configure(); } diff --git a/app/code/Magento/Backend/Console/Command/MaintenanceStatusCommand.php b/app/code/Magento/Backend/Console/Command/MaintenanceStatusCommand.php index e7feae32cf8b0..0f789ae162af0 100644 --- a/app/code/Magento/Backend/Console/Command/MaintenanceStatusCommand.php +++ b/app/code/Magento/Backend/Console/Command/MaintenanceStatusCommand.php @@ -16,6 +16,8 @@ */ class MaintenanceStatusCommand extends AbstractSetupCommand { + const NAME = 'maintenance:status'; + /** * @var MaintenanceMode $maintenanceMode */ @@ -40,7 +42,7 @@ public function __construct(MaintenanceMode $maintenanceMode) */ protected function configure(): void { - $this->setName('maintenance:status') + $this->setName(self::NAME) ->setDescription('Displays maintenance mode status'); parent::configure(); diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/Library/DependencyTest.php b/dev/tests/static/testsuite/Magento/Test/Integrity/Library/DependencyTest.php index c7aecdbf68d88..48201f0d1ad33 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/Library/DependencyTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/Library/DependencyTest.php @@ -39,7 +39,7 @@ protected function getAllowedNamespaces() 'Framework', 'SomeModule', 'ModuleName', - 'Setup\Console\CommandList', + 'Setup\Console\CommandLoader', 'Setup\Console\CompilerPreparation', 'Setup\Model\ObjectManagerProvider', 'Setup\Mvc\Bootstrap\InitParamListener', diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandLoader/AggregateTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandLoader/AggregateTest.php new file mode 100644 index 0000000000000..5a71e7e4858b2 --- /dev/null +++ b/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandLoader/AggregateTest.php @@ -0,0 +1,119 @@ +firstMockCommandLoader = $this->getMockBuilder(CommandLoaderInterface::class)->getMock(); + $this->secondMockCommandLoader = $this->getMockBuilder(CommandLoaderInterface::class)->getMock(); + $this->aggregateCommandLoader = new Aggregate([$this->firstMockCommandLoader, $this->secondMockCommandLoader]); + } + + /** + * Test the various cases of `has` for the aggregate command loader: + * - When at least one "internal" command loader has a command, the aggregate does as well + * - When none of the "internal" command loaders has a command, neither does the aggregate + * + * @dataProvider provideTestCasesForHas + */ + public function testHas(bool $firstResult, bool $secondResult, bool $overallResult) + { + $this->firstMockCommandLoader->method('has')->with('foo')->willReturn($firstResult); + $this->secondMockCommandLoader->method('has')->with('foo')->willReturn($secondResult); + + $this->assertEquals($overallResult, $this->aggregateCommandLoader->has('foo')); + } + + public function provideTestCasesForHas() + { + return [ + [true, false, true], + [false, true, true], + [false, false, false] + ]; + } + + /** + * Test the various cases of `get` for the aggregate command loader. Similar to `has`, + * the return value of `Aggregate::get` mirrors its internal command loaders. + * + * For simplicity, this test does not cover the "no results" case. @see testGetThrow + * + * @dataProvider provideTestCasesForGet + */ + public function testGet(?Command $firstCmd, ?Command $secondCmd) + { + $firstHas = (bool)$firstCmd; + $secondHas = (bool)$secondCmd; + $this->firstMockCommandLoader->method('has')->with('foo')->willReturn($firstHas); + $this->firstMockCommandLoader->method('get')->with('foo')->willReturn($firstCmd); + $this->secondMockCommandLoader->method('has')->with('foo')->willReturn($secondHas); + $this->secondMockCommandLoader->method('get')->with('foo')->willReturn($secondCmd); + + $this->assertInstanceOf(Command::class, $this->aggregateCommandLoader->get('foo')); + } + + public function provideTestCasesForGet() + { + return [ + [ + new Command(), + null + ], + [ + null, + new Command() + ] + ]; + } + + /** + * When none of the internal command loaders have matching commands, the aggregate command loader + * will throw an exception. @see CommandNotFoundException + */ + public function testGetThrow() + { + $this->firstMockCommandLoader->method('has')->with('foo')->willReturn(false); + $this->secondMockCommandLoader->method('has')->with('foo')->willReturn(false); + + $this->expectException(CommandNotFoundException::class); + $this->aggregateCommandLoader->get('foo'); + } + + /** + * An aggregate command loader's `getNames` method returns the merged array of the `getNames` + * return values of all its internal command loaders + */ + public function testGetNames() + { + $this->firstMockCommandLoader->method('getNames')->willReturn(['foo', 'bar']); + $this->secondMockCommandLoader->method('getNames')->willReturn(['baz', 'qux']); + + $this->assertEquals(['foo', 'bar', 'baz', 'qux'], $this->aggregateCommandLoader->getNames()); + } +} diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandLoaderTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandLoaderTest.php new file mode 100644 index 0000000000000..ac3dfec283f4a --- /dev/null +++ b/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandLoaderTest.php @@ -0,0 +1,114 @@ +objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)->getMock(); + } + + /** + * Test that the command loader, when provided zero commands, does not have a command named "foo" + */ + public function testHasWithZeroCommands() + { + $subj = new CommandLoader($this->objectManagerMock, []); + + $this->assertFalse($subj->has('foo')); + } + + /** + * Test that the command loader will return true when provided with a command "foo" + */ + public function testHasWithAtLeastOneCommand() + { + $subj = new CommandLoader($this->objectManagerMock, [ + [ + 'name' => 'foo', + 'class' => FooCommand::class + ] + ]); + + $this->assertTrue($subj->has('foo')); + } + + /** + * Test that the command loader will throw a CommandNotFoundException when it does not have the requested command + */ + public function testGetWithZeroCommands() + { + $subj = new CommandLoader($this->objectManagerMock, []); + + $this->expectException(CommandNotFoundException::class); + + $subj->get('foo'); + } + + /** + * Test that the command loader returns a command when one it has is requested + */ + public function testGetWithAtLeastOneCommand() + { + $this->objectManagerMock + ->method('create') + ->with(FooCommand::class) + ->willReturn(new FooCommand()); + + $subj = new CommandLoader($this->objectManagerMock, [ + [ + 'name' => 'foo', + 'class' => FooCommand::class + ] + ]); + + $this->assertInstanceOf(FooCommand::class, $subj->get('foo')); + } + + /** + * Test that the command loader will return an empty "names" array when it has none + */ + public function testGetNamesWithZeroCommands() + { + $subj = new CommandLoader($this->objectManagerMock, []); + + $this->assertEquals([], $subj->getNames()); + } + + /** + * Test that the command loader returns an array of its command names when `getNames` is called + */ + public function testGetNames() + { + $subj = new CommandLoader($this->objectManagerMock, [ + [ + 'name' => 'foo', + 'class' => FooCommand::class + ], + [ + 'name' => 'bar', + 'class' => 'BarCommand' + ] + ]); + + $this->assertEquals(['foo', 'bar'], $subj->getNames()); + } +} + +// phpcs:ignore PSR1.Classes.ClassDeclaration +class FooCommand extends Command +{ +} diff --git a/lib/internal/Magento/Framework/Console/Cli.php b/lib/internal/Magento/Framework/Console/Cli.php index b38c3dc692e7b..7e2be244819ad 100644 --- a/lib/internal/Magento/Framework/Console/Cli.php +++ b/lib/internal/Magento/Framework/Console/Cli.php @@ -12,16 +12,18 @@ use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\ProductMetadata; use Magento\Framework\Composer\ComposerJsonFinder; +use Magento\Framework\Config\ConfigOptionsListConstants; +use Magento\Framework\Console\CommandLoader\Aggregate; use Magento\Framework\Console\Exception\GenerationDirectoryAccessException; use Magento\Framework\Filesystem\Driver\File; use Magento\Framework\ObjectManagerInterface; use Magento\Framework\Shell\ComplexParameter; use Magento\Setup\Application; +use Magento\Setup\Console\CommandLoader as SetupCommandLoader; use Magento\Setup\Console\CompilerPreparation; use Magento\Setup\Model\ObjectManagerProvider; use Psr\Log\LoggerInterface; use Symfony\Component\Console; -use Magento\Framework\Config\ConfigOptionsListConstants; /** * Magento 2 CLI Application. @@ -102,6 +104,7 @@ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN') parent::__construct($name, $version); $this->serviceManager->setService(\Symfony\Component\Console\Application::class, $this); $this->logger = $this->objectManager->get(LoggerInterface::class); + $this->setCommandLoader($this->getCommandLoader()); } /** @@ -144,11 +147,6 @@ protected function getApplicationCommands() { $commands = []; try { - if (class_exists(\Magento\Setup\Console\CommandList::class)) { - $setupCommandList = new \Magento\Setup\Console\CommandList($this->serviceManager); - $commands = array_merge($commands, $setupCommandList->getCommands()); - } - if ($this->objectManager->get(DeploymentConfig::class)->isAvailable()) { /** @var CommandListInterface */ $commandList = $this->objectManager->create(CommandListInterface::class); @@ -230,4 +228,23 @@ protected function getVendorCommands($objectManager) return array_merge([], ...$commands); } + + /** + * Generate and return the Command Loader + * + * @throws \LogicException + * @throws \BadMethodCallException + */ + private function getCommandLoader(): Console\CommandLoader\CommandLoaderInterface + { + $commandLoaders = []; + if (class_exists(SetupCommandLoader::class)) { + $commandLoaders[] = new SetupCommandLoader($this->serviceManager); + } + $commandLoaders[] = $this->objectManager->create(CommandLoader::class); + + return $this->objectManager->create(Aggregate::class, [ + 'commandLoaders' => $commandLoaders + ]); + } } diff --git a/lib/internal/Magento/Framework/Console/CommandLoader.php b/lib/internal/Magento/Framework/Console/CommandLoader.php new file mode 100644 index 0000000000000..a79b32ec997c7 --- /dev/null +++ b/lib/internal/Magento/Framework/Console/CommandLoader.php @@ -0,0 +1,77 @@ + 'Fully\Qualified\ClassName' ] + * @var array + */ + private $commands; + + /** @var ObjectManagerInterface */ + private $objectManager; + + /** + * @param ObjectManagerInterface $objectManager + * @param array $commands + */ + public function __construct(ObjectManagerInterface $objectManager, array $commands = []) + { + $this->objectManager = $objectManager; + $this->commands = array_combine(array_column($commands, 'name'), array_column($commands, 'class')); + } + + /** + * Using the ObjectManager, instantiate the requested command. + * + * If the command name is not configured, throw a CommandNotFoundException. + * + * @param string $name + * @return \Symfony\Component\Console\Command\Command + * @throws CommandNotFoundException + */ + public function get($name): \Symfony\Component\Console\Command\Command + { + if ($this->has($name)) { + return $this->objectManager->create($this->commands[$name]); + } + throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name)); + } + + /** + * Return whether the requested $name is present in the commands array + * + * @param string $name + * @return bool + */ + public function has($name): bool + { + return isset($this->commands[$name]); + } + + /** + * Return an array of the available command names + * + * @return string[] + */ + public function getNames(): array + { + return array_keys($this->commands); + } +} diff --git a/lib/internal/Magento/Framework/Console/CommandLoader/Aggregate.php b/lib/internal/Magento/Framework/Console/CommandLoader/Aggregate.php new file mode 100644 index 0000000000000..810bed39dfb81 --- /dev/null +++ b/lib/internal/Magento/Framework/Console/CommandLoader/Aggregate.php @@ -0,0 +1,78 @@ +commandLoaders = $commandLoaders; + } + + /** + * Intiantiate and return the command referred to by $name within the internal command loaders. + * + * If $name does not refer to a command, throw a CommandNotFoundException. + * + * @param string $name + * @return \Symfony\Component\Console\Command\Command + * @throws CommandNotFoundException + */ + public function get($name): \Symfony\Component\Console\Command\Command + { + foreach ($this->commandLoaders as $commandLoader) { + if ($commandLoader->has($name)) { + return $commandLoader->get($name); + } + } + + throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name)); + } + + /** + * Return whether $name refers to a command within the internal command loaders. + * + * @param string $name + * @return bool + */ + public function has($name): bool + { + foreach ($this->commandLoaders as $commandLoader) { + if ($commandLoader->has($name)) { + return true; + } + } + + return false; + } + + /** + * Return an array of all the command names provided by the internal command loaders. + * + * @return string[] + */ + public function getNames(): array + { + return array_merge([], ...array_map(function (CommandLoaderInterface $commandLoader) { + return $commandLoader->getNames(); + }, $this->commandLoaders)); + } +} diff --git a/setup/src/Magento/Setup/Console/Command/AdminUserCreateCommand.php b/setup/src/Magento/Setup/Console/Command/AdminUserCreateCommand.php index 8e64aae20573c..82d4b5faf2c7b 100644 --- a/setup/src/Magento/Setup/Console/Command/AdminUserCreateCommand.php +++ b/setup/src/Magento/Setup/Console/Command/AdminUserCreateCommand.php @@ -21,6 +21,7 @@ */ class AdminUserCreateCommand extends AbstractSetupCommand { + const NAME = 'admin:user:create'; /** * @var InstallerFactory */ @@ -49,7 +50,7 @@ public function __construct(InstallerFactory $installerFactory, UserValidationRu */ protected function configure() { - $this->setName('admin:user:create') + $this->setName(self::NAME) ->setDescription('Creates an administrator') ->setDefinition($this->getOptionsList()); parent::configure(); diff --git a/setup/src/Magento/Setup/Console/Command/BackupCommand.php b/setup/src/Magento/Setup/Console/Command/BackupCommand.php index 841e766ebcb90..f065668fb946c 100644 --- a/setup/src/Magento/Setup/Console/Command/BackupCommand.php +++ b/setup/src/Magento/Setup/Console/Command/BackupCommand.php @@ -29,6 +29,7 @@ class BackupCommand extends AbstractSetupCommand const INPUT_KEY_CODE = 'code'; const INPUT_KEY_MEDIA = 'media'; const INPUT_KEY_DB = 'db'; + const NAME = 'setup:backup'; /** * Object Manager @@ -105,7 +106,7 @@ protected function configure() 'Take complete database backup' ), ]; - $this->setName('setup:backup') + $this->setName(self::NAME) ->setDescription('Takes backup of Magento Application code base, media and database') ->setDefinition($options); parent::configure(); diff --git a/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php b/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php index 9380a7b72d6b2..44978b357d65f 100644 --- a/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php @@ -16,6 +16,7 @@ class ConfigSetCommand extends AbstractSetupCommand { + const NAME = 'setup:config:set'; /** * @var ConfigModel */ @@ -60,7 +61,7 @@ protected function configure() { $options = $this->configModel->getAvailableOptions(); - $this->setName('setup:config:set') + $this->setName(self::NAME) ->setDescription('Creates or modifies the deployment configuration') ->setDefinition($options); diff --git a/setup/src/Magento/Setup/Console/Command/DbDataUpgradeCommand.php b/setup/src/Magento/Setup/Console/Command/DbDataUpgradeCommand.php index ae0c2f5c4e27f..035573d51bc46 100644 --- a/setup/src/Magento/Setup/Console/Command/DbDataUpgradeCommand.php +++ b/setup/src/Magento/Setup/Console/Command/DbDataUpgradeCommand.php @@ -17,6 +17,7 @@ */ class DbDataUpgradeCommand extends AbstractSetupCommand { + const NAME = 'setup:db-data:upgrade'; /** * Factory to create installer * @@ -51,7 +52,7 @@ public function __construct(InstallerFactory $installFactory, DeploymentConfig $ */ protected function configure() { - $this->setName('setup:db-data:upgrade')->setDescription('Installs and upgrades data in the DB'); + $this->setName(self::NAME)->setDescription('Installs and upgrades data in the DB'); parent::configure(); } diff --git a/setup/src/Magento/Setup/Console/Command/DbSchemaUpgradeCommand.php b/setup/src/Magento/Setup/Console/Command/DbSchemaUpgradeCommand.php index 3ef9a441b868f..06e038170640f 100644 --- a/setup/src/Magento/Setup/Console/Command/DbSchemaUpgradeCommand.php +++ b/setup/src/Magento/Setup/Console/Command/DbSchemaUpgradeCommand.php @@ -18,6 +18,7 @@ */ class DbSchemaUpgradeCommand extends AbstractSetupCommand { + const NAME = 'setup:db-schema:upgrade'; /** * Factory to create installer. * @@ -53,7 +54,7 @@ public function __construct(InstallerFactory $installFactory, DeploymentConfig $ protected function configure() { $this - ->setName('setup:db-schema:upgrade') + ->setName(self::NAME) ->setDefinition( [ new InputOption( diff --git a/setup/src/Magento/Setup/Console/Command/DbStatusCommand.php b/setup/src/Magento/Setup/Console/Command/DbStatusCommand.php index be18bd58037ea..eeb02d532ab93 100644 --- a/setup/src/Magento/Setup/Console/Command/DbStatusCommand.php +++ b/setup/src/Magento/Setup/Console/Command/DbStatusCommand.php @@ -25,6 +25,7 @@ class DbStatusCommand extends AbstractSetupCommand * Code for error when application upgrade is required. */ const EXIT_CODE_UPGRADE_REQUIRED = 2; + const NAME = 'setup:db:status'; /** * Object manager provider @@ -73,7 +74,7 @@ public function __construct(ObjectManagerProvider $objectManagerProvider, Deploy */ protected function configure() { - $this->setName('setup:db:status') + $this->setName(self::NAME) ->setDescription('Checks if DB schema or data requires upgrade'); parent::configure(); } diff --git a/setup/src/Magento/Setup/Console/Command/DependenciesShowFrameworkCommand.php b/setup/src/Magento/Setup/Console/Command/DependenciesShowFrameworkCommand.php index 3ea98d7aa252d..6d4a6389ca42e 100644 --- a/setup/src/Magento/Setup/Console/Command/DependenciesShowFrameworkCommand.php +++ b/setup/src/Magento/Setup/Console/Command/DependenciesShowFrameworkCommand.php @@ -16,6 +16,7 @@ */ class DependenciesShowFrameworkCommand extends AbstractDependenciesCommand { + const NAME = 'info:dependencies:show-framework'; /** * @var ComponentRegistrarInterface */ @@ -39,7 +40,7 @@ public function __construct(ComponentRegistrarInterface $registrar, ObjectManage protected function configure() { $this->setDescription('Shows number of dependencies on Magento framework') - ->setName('info:dependencies:show-framework'); + ->setName(self::NAME); parent::configure(); } diff --git a/setup/src/Magento/Setup/Console/Command/DependenciesShowModulesCircularCommand.php b/setup/src/Magento/Setup/Console/Command/DependenciesShowModulesCircularCommand.php index c9cfdd7526136..3323ebaa5cd09 100644 --- a/setup/src/Magento/Setup/Console/Command/DependenciesShowModulesCircularCommand.php +++ b/setup/src/Magento/Setup/Console/Command/DependenciesShowModulesCircularCommand.php @@ -14,13 +14,15 @@ */ class DependenciesShowModulesCircularCommand extends AbstractDependenciesCommand { + const NAME = 'info:dependencies:show-modules-circular'; + /** * {@inheritdoc} */ protected function configure() { $this->setDescription('Shows number of circular dependencies between modules') - ->setName('info:dependencies:show-modules-circular'); + ->setName(self::NAME); parent::configure(); } diff --git a/setup/src/Magento/Setup/Console/Command/DependenciesShowModulesCommand.php b/setup/src/Magento/Setup/Console/Command/DependenciesShowModulesCommand.php index 13499b56412a1..d087ad05e4f20 100644 --- a/setup/src/Magento/Setup/Console/Command/DependenciesShowModulesCommand.php +++ b/setup/src/Magento/Setup/Console/Command/DependenciesShowModulesCommand.php @@ -14,13 +14,15 @@ */ class DependenciesShowModulesCommand extends AbstractDependenciesCommand { + const NAME = 'info:dependencies:show-modules'; + /** * {@inheritdoc} */ protected function configure() { $this->setDescription('Shows number of dependencies between modules') - ->setName('info:dependencies:show-modules'); + ->setName(self::NAME); parent::configure(); } diff --git a/setup/src/Magento/Setup/Console/Command/DeployStaticContentCommand.php b/setup/src/Magento/Setup/Console/Command/DeployStaticContentCommand.php index 1afdd86cdff3f..9e281ce4bf829 100644 --- a/setup/src/Magento/Setup/Console/Command/DeployStaticContentCommand.php +++ b/setup/src/Magento/Setup/Console/Command/DeployStaticContentCommand.php @@ -32,6 +32,7 @@ class DeployStaticContentCommand extends Command * Default language value. Always used for adminhtml, fallback if no frontend locale is supplied. */ const DEFAULT_LANGUAGE_VALUE = 'en_US'; + const NAME = 'setup:static-content:deploy'; /** * @var InputValidator @@ -90,7 +91,7 @@ public function __construct( */ protected function configure() { - $this->setName('setup:static-content:deploy') + $this->setName(self::NAME) ->setDescription('Deploys static view files') ->setDefinition($this->options->getOptionsList()); diff --git a/setup/src/Magento/Setup/Console/Command/GenerateFixturesCommand.php b/setup/src/Magento/Setup/Console/Command/GenerateFixturesCommand.php index 24e370758e317..967da5415f879 100644 --- a/setup/src/Magento/Setup/Console/Command/GenerateFixturesCommand.php +++ b/setup/src/Magento/Setup/Console/Command/GenerateFixturesCommand.php @@ -25,6 +25,8 @@ class GenerateFixturesCommand extends Command public const SKIP_REINDEX_OPTION = 'skip-reindex'; + public const NAME = 'setup:performance:generate-fixtures'; + /** * @var FixtureModel */ @@ -44,7 +46,7 @@ public function __construct(FixtureModel $fixtureModel) */ protected function configure() { - $this->setName('setup:performance:generate-fixtures') + $this->setName(self::NAME) ->setDescription('Generates fixtures') ->setDefinition([ new InputArgument( diff --git a/setup/src/Magento/Setup/Console/Command/I18nCollectPhrasesCommand.php b/setup/src/Magento/Setup/Console/Command/I18nCollectPhrasesCommand.php index bb8ab4e4cc49a..e3627cf78ef27 100644 --- a/setup/src/Magento/Setup/Console/Command/I18nCollectPhrasesCommand.php +++ b/setup/src/Magento/Setup/Console/Command/I18nCollectPhrasesCommand.php @@ -25,6 +25,7 @@ class I18nCollectPhrasesCommand extends Command const SHORTCUT_KEY_OUTPUT = 'o'; const INPUT_KEY_MAGENTO = 'magento'; const SHORTCUT_KEY_MAGENTO = 'm'; + const NAME = 'i18n:collect-phrases'; /**#@- */ /** @@ -32,7 +33,7 @@ class I18nCollectPhrasesCommand extends Command */ protected function configure() { - $this->setName('i18n:collect-phrases') + $this->setName(self::NAME) ->setDescription('Discovers phrases in the codebase'); $this->setDefinition([ new InputArgument( diff --git a/setup/src/Magento/Setup/Console/Command/I18nPackCommand.php b/setup/src/Magento/Setup/Console/Command/I18nPackCommand.php index 7c5cc89387dcf..e3cf86bebef46 100644 --- a/setup/src/Magento/Setup/Console/Command/I18nPackCommand.php +++ b/setup/src/Magento/Setup/Console/Command/I18nPackCommand.php @@ -35,13 +35,14 @@ class I18nPackCommand extends Command * 'merge' mode value */ const MODE_MERGE = 'merge'; + const NAME = 'i18n:pack'; /** * {@inheritdoc} */ protected function configure() { - $this->setName('i18n:pack') + $this->setName(self::NAME) ->setDescription('Saves language package'); $this->setDefinition([ new InputArgument( diff --git a/setup/src/Magento/Setup/Console/Command/InfoAdminUriCommand.php b/setup/src/Magento/Setup/Console/Command/InfoAdminUriCommand.php index 006afc27a0826..a8d710a7f060d 100644 --- a/setup/src/Magento/Setup/Console/Command/InfoAdminUriCommand.php +++ b/setup/src/Magento/Setup/Console/Command/InfoAdminUriCommand.php @@ -13,6 +13,7 @@ class InfoAdminUriCommand extends Command { + const NAME = 'info:adminuri'; /** * @var \Magento\Framework\App\DeploymentConfig */ @@ -38,7 +39,7 @@ public function __construct(\Magento\Framework\App\DeploymentConfig $deploymentC */ protected function configure() { - $this->setName('info:adminuri') + $this->setName(self::NAME) ->setDescription('Displays the Magento Admin URI'); parent::configure(); } diff --git a/setup/src/Magento/Setup/Console/Command/InfoBackupsListCommand.php b/setup/src/Magento/Setup/Console/Command/InfoBackupsListCommand.php index 94337dd0742e3..07f8f0900f82a 100644 --- a/setup/src/Magento/Setup/Console/Command/InfoBackupsListCommand.php +++ b/setup/src/Magento/Setup/Console/Command/InfoBackupsListCommand.php @@ -21,6 +21,7 @@ */ class InfoBackupsListCommand extends Command { + const NAME = 'info:backups:list'; /** * File * @@ -61,7 +62,7 @@ public function __construct( */ protected function configure() { - $this->setName('info:backups:list') + $this->setName(self::NAME) ->setDescription('Prints list of available backup files'); parent::configure(); diff --git a/setup/src/Magento/Setup/Console/Command/InfoCurrencyListCommand.php b/setup/src/Magento/Setup/Console/Command/InfoCurrencyListCommand.php index 91cfb5e7f6b5c..c2dbe0ba0aaf9 100644 --- a/setup/src/Magento/Setup/Console/Command/InfoCurrencyListCommand.php +++ b/setup/src/Magento/Setup/Console/Command/InfoCurrencyListCommand.php @@ -18,6 +18,7 @@ */ class InfoCurrencyListCommand extends Command { + const NAME = 'info:currency:list'; /** * List model provides lists of available options for currency, language locales, timezones * @@ -46,7 +47,7 @@ public function __construct(Lists $lists, TableFactory $tableHelperFactory = nul */ protected function configure() { - $this->setName('info:currency:list') + $this->setName(self::NAME) ->setDescription('Displays the list of available currencies'); parent::configure(); diff --git a/setup/src/Magento/Setup/Console/Command/InfoLanguageListCommand.php b/setup/src/Magento/Setup/Console/Command/InfoLanguageListCommand.php index 8950bd5edb2fa..34f6171e04999 100644 --- a/setup/src/Magento/Setup/Console/Command/InfoLanguageListCommand.php +++ b/setup/src/Magento/Setup/Console/Command/InfoLanguageListCommand.php @@ -18,6 +18,7 @@ */ class InfoLanguageListCommand extends Command { + const NAME = 'info:language:list'; /** * List model provides lists of available options for currency, language locales, timezones * @@ -46,7 +47,7 @@ public function __construct(Lists $lists, TableFactory $tableHelperFactory = nul */ protected function configure() { - $this->setName('info:language:list') + $this->setName(self::NAME) ->setDescription('Displays the list of available language locales'); parent::configure(); diff --git a/setup/src/Magento/Setup/Console/Command/InfoTimezoneListCommand.php b/setup/src/Magento/Setup/Console/Command/InfoTimezoneListCommand.php index 2ff1d228dfe24..84f2455675ab4 100644 --- a/setup/src/Magento/Setup/Console/Command/InfoTimezoneListCommand.php +++ b/setup/src/Magento/Setup/Console/Command/InfoTimezoneListCommand.php @@ -18,6 +18,7 @@ */ class InfoTimezoneListCommand extends Command { + const NAME = 'info:timezone:list'; /** * List model provides lists of available options for currency, language locales, timezones * @@ -46,7 +47,7 @@ public function __construct(Lists $lists, TableFactory $tableHelperFactory = nul */ protected function configure() { - $this->setName('info:timezone:list') + $this->setName(self::NAME) ->setDescription('Displays the list of available timezones'); parent::configure(); diff --git a/setup/src/Magento/Setup/Console/Command/InstallCommand.php b/setup/src/Magento/Setup/Console/Command/InstallCommand.php index 1f716043c3846..e0da147bd664c 100644 --- a/setup/src/Magento/Setup/Console/Command/InstallCommand.php +++ b/setup/src/Magento/Setup/Console/Command/InstallCommand.php @@ -89,6 +89,8 @@ class InstallCommand extends AbstractSetupCommand */ public const SALES_ORDER_INCREMENT_PREFIX_RULE = '/^.{0,20}$/'; + public const NAME = 'setup:install'; + /** * Installer service factory * @@ -220,7 +222,7 @@ protected function configure() false ), ]); - $this->setName('setup:install') + $this->setName(self::NAME) ->setDescription('Installs the Magento application') ->setDefinition($inputOptions); parent::configure(); diff --git a/setup/src/Magento/Setup/Console/Command/InstallStoreConfigurationCommand.php b/setup/src/Magento/Setup/Console/Command/InstallStoreConfigurationCommand.php index 7eb8aec274888..3e398238f4979 100644 --- a/setup/src/Magento/Setup/Console/Command/InstallStoreConfigurationCommand.php +++ b/setup/src/Magento/Setup/Console/Command/InstallStoreConfigurationCommand.php @@ -26,6 +26,7 @@ */ class InstallStoreConfigurationCommand extends AbstractSetupCommand { + const NAME = 'setup:store-config:set'; /** * @var InstallerFactory */ @@ -101,7 +102,7 @@ public function __construct( */ protected function configure() { - $this->setName('setup:store-config:set') + $this->setName(self::NAME) ->setDescription('Installs the store configuration. Deprecated since 2.2.0. Use config:set instead') ->setDefinition($this->getOptionsList()); parent::configure(); diff --git a/setup/src/Magento/Setup/Console/Command/ModuleConfigStatusCommand.php b/setup/src/Magento/Setup/Console/Command/ModuleConfigStatusCommand.php index 70dbf14728bd7..ae76f66892bf1 100644 --- a/setup/src/Magento/Setup/Console/Command/ModuleConfigStatusCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ModuleConfigStatusCommand.php @@ -23,6 +23,7 @@ */ class ModuleConfigStatusCommand extends Command { + const NAME = 'module:config:status'; /** * Deployment config reader * @@ -57,7 +58,7 @@ public function __construct( protected function configure() { $this - ->setName('module:config:status') + ->setName(self::NAME) ->setDescription( 'Checks the modules configuration in the \'app/etc/config.php\' file ' . 'and reports if they are up to date or not' diff --git a/setup/src/Magento/Setup/Console/Command/ModuleDisableCommand.php b/setup/src/Magento/Setup/Console/Command/ModuleDisableCommand.php index cf3dd328616ba..a95e3f6bb757d 100644 --- a/setup/src/Magento/Setup/Console/Command/ModuleDisableCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ModuleDisableCommand.php @@ -10,12 +10,14 @@ */ class ModuleDisableCommand extends AbstractModuleManageCommand { + const NAME = 'module:disable'; + /** * {@inheritdoc} */ protected function configure() { - $this->setName('module:disable') + $this->setName(self::NAME) ->setDescription('Disables specified modules'); parent::configure(); } diff --git a/setup/src/Magento/Setup/Console/Command/ModuleEnableCommand.php b/setup/src/Magento/Setup/Console/Command/ModuleEnableCommand.php index 62a514ada9b8d..47588567fe1aa 100644 --- a/setup/src/Magento/Setup/Console/Command/ModuleEnableCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ModuleEnableCommand.php @@ -10,12 +10,14 @@ */ class ModuleEnableCommand extends AbstractModuleManageCommand { + const NAME = 'module:enable'; + /** * {@inheritdoc} */ protected function configure() { - $this->setName('module:enable') + $this->setName(self::NAME) ->setDescription('Enables specified modules'); parent::configure(); } diff --git a/setup/src/Magento/Setup/Console/Command/ModuleStatusCommand.php b/setup/src/Magento/Setup/Console/Command/ModuleStatusCommand.php index 4e5e73f53478e..403c0307b087b 100644 --- a/setup/src/Magento/Setup/Console/Command/ModuleStatusCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ModuleStatusCommand.php @@ -21,6 +21,7 @@ */ class ModuleStatusCommand extends AbstractSetupCommand { + const NAME = 'module:status'; /** * @var ObjectManagerProvider */ @@ -40,7 +41,7 @@ public function __construct(ObjectManagerProvider $objectManagerProvider) */ protected function configure() { - $this->setName('module:status') + $this->setName(self::NAME) ->setDescription('Displays status of modules') ->addArgument( 'module-names', diff --git a/setup/src/Magento/Setup/Console/Command/ModuleUninstallCommand.php b/setup/src/Magento/Setup/Console/Command/ModuleUninstallCommand.php index 5754bbca986c8..cf4d703b6c3fd 100644 --- a/setup/src/Magento/Setup/Console/Command/ModuleUninstallCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ModuleUninstallCommand.php @@ -41,6 +41,7 @@ class ModuleUninstallCommand extends AbstractModuleCommand const INPUT_KEY_BACKUP_MEDIA = 'backup-media'; const INPUT_KEY_BACKUP_DB = 'backup-db'; const INPUT_KEY_NON_COMPOSER_MODULE = 'non-composer'; + const NAME = 'module:uninstall'; /** * Deployment Configuration @@ -205,7 +206,7 @@ protected function configure() 'All modules, that will be past here will be non composer based' ) ]; - $this->setName('module:uninstall') + $this->setName(self::NAME) ->setDescription('Uninstalls modules installed by composer') ->setDefinition($options); parent::configure(); diff --git a/setup/src/Magento/Setup/Console/Command/RollbackCommand.php b/setup/src/Magento/Setup/Console/Command/RollbackCommand.php index e114c84ba79bc..1deaf642b93d4 100644 --- a/setup/src/Magento/Setup/Console/Command/RollbackCommand.php +++ b/setup/src/Magento/Setup/Console/Command/RollbackCommand.php @@ -30,6 +30,7 @@ class RollbackCommand extends AbstractSetupCommand const INPUT_KEY_CODE_BACKUP_FILE = 'code-file'; const INPUT_KEY_MEDIA_BACKUP_FILE = 'media-file'; const INPUT_KEY_DB_BACKUP_FILE = 'db-file'; + const NAME = 'setup:rollback'; /** * Object Manager @@ -104,7 +105,7 @@ protected function configure() 'Basename of the db backup file in var/backups' ), ]; - $this->setName('setup:rollback') + $this->setName(self::NAME) ->setDescription('Rolls back Magento Application codebase, media and database') ->setDefinition($options); parent::configure(); diff --git a/setup/src/Magento/Setup/Console/Command/UninstallCommand.php b/setup/src/Magento/Setup/Console/Command/UninstallCommand.php index 0163ef3846c83..58a8f901fee94 100644 --- a/setup/src/Magento/Setup/Console/Command/UninstallCommand.php +++ b/setup/src/Magento/Setup/Console/Command/UninstallCommand.php @@ -14,6 +14,7 @@ class UninstallCommand extends AbstractSetupCommand { + const NAME = 'setup:uninstall'; /** * @var InstallerFactory */ @@ -33,7 +34,7 @@ public function __construct(InstallerFactory $installerFactory) */ protected function configure() { - $this->setName('setup:uninstall') + $this->setName(self::NAME) ->setDescription('Uninstalls the Magento application'); parent::configure(); } diff --git a/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php b/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php index 84a0897ace10d..4fc8550e38509 100644 --- a/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php +++ b/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php @@ -35,6 +35,8 @@ class UpgradeCommand extends AbstractSetupCommand */ public const INPUT_KEY_KEEP_GENERATED = 'keep-generated'; + public const NAME = 'setup:upgrade'; + /** * Installer service factory. * @@ -125,7 +127,7 @@ protected function configure() false ) ]; - $this->setName('setup:upgrade') + $this->setName(self::NAME) ->setDescription('Upgrades the Magento application, DB data, and schema') ->setDefinition($options); parent::configure(); diff --git a/setup/src/Magento/Setup/Console/CommandList.php b/setup/src/Magento/Setup/Console/CommandList.php deleted file mode 100644 index ae65e82bba12b..0000000000000 --- a/setup/src/Magento/Setup/Console/CommandList.php +++ /dev/null @@ -1,97 +0,0 @@ -serviceManager = $serviceManager; - } - - /** - * Gets list of setup command classes - * - * @return string[] - */ - protected function getCommandsClasses() - { - return [ - \Magento\Setup\Console\Command\AdminUserCreateCommand::class, - \Magento\Setup\Console\Command\BackupCommand::class, - \Magento\Setup\Console\Command\ConfigSetCommand::class, - \Magento\Setup\Console\Command\DbDataUpgradeCommand::class, - \Magento\Setup\Console\Command\DbSchemaUpgradeCommand::class, - \Magento\Setup\Console\Command\DbStatusCommand::class, - \Magento\Setup\Console\Command\DependenciesShowFrameworkCommand::class, - \Magento\Setup\Console\Command\DependenciesShowModulesCircularCommand::class, - \Magento\Setup\Console\Command\DependenciesShowModulesCommand::class, - \Magento\Setup\Console\Command\DiCompileCommand::class, - \Magento\Setup\Console\Command\GenerateFixturesCommand::class, - \Magento\Setup\Console\Command\I18nCollectPhrasesCommand::class, - \Magento\Setup\Console\Command\I18nPackCommand::class, - \Magento\Setup\Console\Command\InfoAdminUriCommand::class, - \Magento\Setup\Console\Command\InfoBackupsListCommand::class, - \Magento\Setup\Console\Command\InfoCurrencyListCommand::class, - \Magento\Setup\Console\Command\InfoLanguageListCommand::class, - \Magento\Setup\Console\Command\InfoTimezoneListCommand::class, - \Magento\Setup\Console\Command\InstallCommand::class, - \Magento\Setup\Console\Command\InstallStoreConfigurationCommand::class, - \Magento\Setup\Console\Command\ModuleEnableCommand::class, - \Magento\Setup\Console\Command\ModuleDisableCommand::class, - \Magento\Setup\Console\Command\ModuleStatusCommand::class, - \Magento\Setup\Console\Command\ModuleUninstallCommand::class, - \Magento\Setup\Console\Command\ModuleConfigStatusCommand::class, - \Magento\Setup\Console\Command\RollbackCommand::class, - \Magento\Setup\Console\Command\UpgradeCommand::class, - \Magento\Setup\Console\Command\UninstallCommand::class, - \Magento\Setup\Console\Command\DeployStaticContentCommand::class - ]; - } - - /** - * Gets list of command instances. - * - * @return \Symfony\Component\Console\Command\Command[] - * @throws \Exception - */ - public function getCommands() - { - $commands = []; - - foreach ($this->getCommandsClasses() as $class) { - if (class_exists($class)) { - $commands[] = $this->serviceManager->get($class); - } else { - // phpcs:ignore Magento2.Exceptions.DirectThrow - throw new \Exception('Class ' . $class . ' does not exist'); - } - } - - return $commands; - } -} diff --git a/setup/src/Magento/Setup/Console/CommandLoader.php b/setup/src/Magento/Setup/Console/CommandLoader.php new file mode 100644 index 0000000000000..6142681f140fb --- /dev/null +++ b/setup/src/Magento/Setup/Console/CommandLoader.php @@ -0,0 +1,113 @@ + Command\AdminUserCreateCommand::class, + Command\BackupCommand::NAME => Command\BackupCommand::class, + Command\ConfigSetCommand::NAME => Command\ConfigSetCommand::class, + Command\DbDataUpgradeCommand::NAME => Command\DbDataUpgradeCommand::class, + Command\DbSchemaUpgradeCommand::NAME => Command\DbSchemaUpgradeCommand::class, + Command\DbStatusCommand::NAME => Command\DbStatusCommand::class, + Command\DependenciesShowFrameworkCommand::NAME => Command\DependenciesShowFrameworkCommand::class, + Command\DependenciesShowModulesCircularCommand::NAME => Command\DependenciesShowModulesCircularCommand::class, + Command\DependenciesShowModulesCommand::NAME => Command\DependenciesShowModulesCommand::class, + Command\DiCompileCommand::NAME => Command\DiCompileCommand::class, + Command\GenerateFixturesCommand::NAME => Command\GenerateFixturesCommand::class, + Command\I18nCollectPhrasesCommand::NAME => Command\I18nCollectPhrasesCommand::class, + Command\I18nPackCommand::NAME => Command\I18nPackCommand::class, + Command\InfoAdminUriCommand::NAME => Command\InfoAdminUriCommand::class, + Command\InfoBackupsListCommand::NAME => Command\InfoBackupsListCommand::class, + Command\InfoCurrencyListCommand::NAME => Command\InfoCurrencyListCommand::class, + Command\InfoLanguageListCommand::NAME => Command\InfoLanguageListCommand::class, + Command\InfoTimezoneListCommand::NAME => Command\InfoTimezoneListCommand::class, + Command\InstallCommand::NAME => Command\InstallCommand::class, + Command\InstallStoreConfigurationCommand::NAME => Command\InstallStoreConfigurationCommand::class, + Command\ModuleEnableCommand::NAME => Command\ModuleEnableCommand::class, + Command\ModuleDisableCommand::NAME => Command\ModuleDisableCommand::class, + Command\ModuleStatusCommand::NAME => Command\ModuleStatusCommand::class, + Command\ModuleUninstallCommand::NAME => Command\ModuleUninstallCommand::class, + Command\ModuleConfigStatusCommand::NAME => Command\ModuleConfigStatusCommand::class, + Command\RollbackCommand::NAME => Command\RollbackCommand::class, + Command\UpgradeCommand::NAME => Command\UpgradeCommand::class, + Command\UninstallCommand::NAME => Command\UninstallCommand::class, + Command\DeployStaticContentCommand::NAME => Command\DeployStaticContentCommand::class + ]; + + /** + * Constructor + * + * @param ServiceManager $serviceManager + */ + public function __construct(ServiceManager $serviceManager) + { + $this->serviceManager = $serviceManager; + } + + /** + * Generate a symfony console command with the laminas service manager + * + * @param string $name + * @return SymfonyCommand + * @throws CommandNotFoundException + */ + public function get($name): SymfonyCommand + { + if ($this->has($name)) { + /** @var SymfonyCommand $command */ + $command = $this->serviceManager->get($this->commands[$name]); + return $command; + } + + throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name)); + } + + /** + * Return whether the command loader has a command configured for given $name + * + * @param string $name + * @return bool + */ + public function has($name): bool + { + return isset($this->commands[$name]); + } + + /** + * Return the list of configured commands for the command loader + * + * @return string[] + */ + public function getNames(): array + { + return array_keys($this->commands); + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Console/CommandListTest.php b/setup/src/Magento/Setup/Test/Unit/Console/CommandListTest.php deleted file mode 100644 index 09b756433be28..0000000000000 --- a/setup/src/Magento/Setup/Test/Unit/Console/CommandListTest.php +++ /dev/null @@ -1,40 +0,0 @@ -serviceManager = $this->createMock(ServiceManager::class); - $this->commandList = new CommandList($this->serviceManager); - } - - public function testGetCommands() - { - $this->serviceManager->expects($this->atLeastOnce()) - ->method('get'); - - $this->commandList->getCommands(); - } -} diff --git a/setup/src/Magento/Setup/Test/Unit/Console/CommandLoaderTest.php b/setup/src/Magento/Setup/Test/Unit/Console/CommandLoaderTest.php new file mode 100644 index 0000000000000..da7fef93f73b6 --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Console/CommandLoaderTest.php @@ -0,0 +1,45 @@ +serviceManager = $this->createMock(ServiceManager::class); + $this->commandLoader = new CommandLoader($this->serviceManager); + } + + public function testServiceManagerIsUsedToInitializeCommands() + { + $command = $this->getMockBuilder(\Symfony\Component\Console\Command\Command::class) + ->disableOriginalConstructor() + ->getMock(); + $this->serviceManager->expects($this->once()) + ->method('get') + ->willReturn($command); + + $firstCommandName = current($this->commandLoader->getNames()); + $this->commandLoader->get($firstCommandName); + } +} From 764a2c61b5a8ee198df170c7762d5ea53a795d91 Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Mon, 9 Oct 2023 10:12:13 +0300 Subject: [PATCH 2/4] Implement command loader Fix test failures --- .../Command/MaintenanceAllowIpsCommand.php | 8 ++--- .../Command/MaintenanceDisableCommand.php | 2 +- .../Command/MaintenanceEnableCommand.php | 2 +- .../Command/MaintenanceStatusCommand.php | 2 +- .../Console/CommandLoader/AggregateTest.php | 23 +++++++------ .../Test/Unit/Console/CommandLoaderTest.php | 18 +++++----- .../Magento/Framework/Console/Cli.php | 13 +++---- .../Framework/Console/CommandLoader.php | 12 +++---- .../Console/CommandLoader/Aggregate.php | 11 +++--- .../Command/AdminUserCreateCommand.php | 2 +- .../Setup/Console/Command/BackupCommand.php | 14 ++++---- .../Console/Command/ConfigSetCommand.php | 3 +- .../Console/Command/DbDataUpgradeCommand.php | 4 +-- .../Command/DbSchemaUpgradeCommand.php | 4 +-- .../Setup/Console/Command/DbStatusCommand.php | 10 +++--- .../DependenciesShowFrameworkCommand.php | 4 +-- ...DependenciesShowModulesCircularCommand.php | 4 +-- .../DependenciesShowModulesCommand.php | 4 +-- .../Command/DeployStaticContentCommand.php | 4 +-- .../Command/I18nCollectPhrasesCommand.php | 16 ++++----- .../Setup/Console/Command/I18nPackCommand.php | 18 +++++----- .../Console/Command/InfoAdminUriCommand.php | 4 +-- .../Command/InfoBackupsListCommand.php | 8 ++--- .../Command/InfoCurrencyListCommand.php | 6 ++-- .../Command/InfoLanguageListCommand.php | 6 ++-- .../Command/InfoTimezoneListCommand.php | 6 ++-- .../InstallStoreConfigurationCommand.php | 34 ++++++------------- .../Command/ModuleConfigStatusCommand.php | 2 +- .../Console/Command/ModuleDisableCommand.php | 4 +-- .../Console/Command/ModuleEnableCommand.php | 4 +-- .../Console/Command/ModuleStatusCommand.php | 2 +- .../Command/ModuleUninstallCommand.php | 28 ++++++--------- .../Setup/Console/Command/RollbackCommand.php | 10 +++--- .../Console/Command/UninstallCommand.php | 6 ++-- .../Magento/Setup/Console/CommandLoader.php | 11 +++--- .../InstallStoreConfigurationCommandTest.php | 14 +------- .../Test/Unit/Console/CommandLoaderTest.php | 9 ++--- 37 files changed, 149 insertions(+), 183 deletions(-) diff --git a/app/code/Magento/Backend/Console/Command/MaintenanceAllowIpsCommand.php b/app/code/Magento/Backend/Console/Command/MaintenanceAllowIpsCommand.php index 86c5e59ba91ee..e6d3db449621e 100644 --- a/app/code/Magento/Backend/Console/Command/MaintenanceAllowIpsCommand.php +++ b/app/code/Magento/Backend/Console/Command/MaintenanceAllowIpsCommand.php @@ -22,10 +22,10 @@ class MaintenanceAllowIpsCommand extends AbstractSetupCommand /** * Names of input arguments or options */ - const INPUT_KEY_IP = 'ip'; - const INPUT_KEY_NONE = 'none'; - const INPUT_KEY_ADD = 'add'; - const NAME = 'maintenance:allow-ips'; + public const INPUT_KEY_IP = 'ip'; + public const INPUT_KEY_NONE = 'none'; + public const INPUT_KEY_ADD = 'add'; + public const NAME = 'maintenance:allow-ips'; /** * @var MaintenanceMode diff --git a/app/code/Magento/Backend/Console/Command/MaintenanceDisableCommand.php b/app/code/Magento/Backend/Console/Command/MaintenanceDisableCommand.php index 34b6c2e9c9e90..4bbe374d26f76 100644 --- a/app/code/Magento/Backend/Console/Command/MaintenanceDisableCommand.php +++ b/app/code/Magento/Backend/Console/Command/MaintenanceDisableCommand.php @@ -10,7 +10,7 @@ */ class MaintenanceDisableCommand extends AbstractMaintenanceCommand { - const NAME = 'maintenance:disable'; + public const NAME = 'maintenance:disable'; /** * Initialization of the command diff --git a/app/code/Magento/Backend/Console/Command/MaintenanceEnableCommand.php b/app/code/Magento/Backend/Console/Command/MaintenanceEnableCommand.php index ca8c33f0c31fc..38851f139b0bb 100644 --- a/app/code/Magento/Backend/Console/Command/MaintenanceEnableCommand.php +++ b/app/code/Magento/Backend/Console/Command/MaintenanceEnableCommand.php @@ -10,7 +10,7 @@ */ class MaintenanceEnableCommand extends AbstractMaintenanceCommand { - const NAME = 'maintenance:enable'; + public const NAME = 'maintenance:enable'; /** * Initialization of the command diff --git a/app/code/Magento/Backend/Console/Command/MaintenanceStatusCommand.php b/app/code/Magento/Backend/Console/Command/MaintenanceStatusCommand.php index 0f789ae162af0..40dc483862b37 100644 --- a/app/code/Magento/Backend/Console/Command/MaintenanceStatusCommand.php +++ b/app/code/Magento/Backend/Console/Command/MaintenanceStatusCommand.php @@ -16,7 +16,7 @@ */ class MaintenanceStatusCommand extends AbstractSetupCommand { - const NAME = 'maintenance:status'; + public const NAME = 'maintenance:status'; /** * @var MaintenanceMode $maintenanceMode diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandLoader/AggregateTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandLoader/AggregateTest.php index 5a71e7e4858b2..7c25c3262abe8 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandLoader/AggregateTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandLoader/AggregateTest.php @@ -1,4 +1,5 @@ firstMockCommandLoader->method('has')->with('foo')->willReturn($firstResult); $this->secondMockCommandLoader->method('has')->with('foo')->willReturn($secondResult); @@ -49,7 +50,7 @@ public function testHas(bool $firstResult, bool $secondResult, bool $overallResu $this->assertEquals($overallResult, $this->aggregateCommandLoader->has('foo')); } - public function provideTestCasesForHas() + public function provideTestCasesForHas(): array { return [ [true, false, true], @@ -66,7 +67,7 @@ public function provideTestCasesForHas() * * @dataProvider provideTestCasesForGet */ - public function testGet(?Command $firstCmd, ?Command $secondCmd) + public function testGet(?Command $firstCmd, ?Command $secondCmd): void { $firstHas = (bool)$firstCmd; $secondHas = (bool)$secondCmd; @@ -78,7 +79,7 @@ public function testGet(?Command $firstCmd, ?Command $secondCmd) $this->assertInstanceOf(Command::class, $this->aggregateCommandLoader->get('foo')); } - public function provideTestCasesForGet() + public function provideTestCasesForGet(): array { return [ [ @@ -96,7 +97,7 @@ public function provideTestCasesForGet() * When none of the internal command loaders have matching commands, the aggregate command loader * will throw an exception. @see CommandNotFoundException */ - public function testGetThrow() + public function testGetThrow(): void { $this->firstMockCommandLoader->method('has')->with('foo')->willReturn(false); $this->secondMockCommandLoader->method('has')->with('foo')->willReturn(false); @@ -109,7 +110,7 @@ public function testGetThrow() * An aggregate command loader's `getNames` method returns the merged array of the `getNames` * return values of all its internal command loaders */ - public function testGetNames() + public function testGetNames(): void { $this->firstMockCommandLoader->method('getNames')->willReturn(['foo', 'bar']); $this->secondMockCommandLoader->method('getNames')->willReturn(['baz', 'qux']); diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandLoaderTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandLoaderTest.php index ac3dfec283f4a..c31c5b5a92a33 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandLoaderTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandLoaderTest.php @@ -1,4 +1,5 @@ objectManagerMock, []); @@ -34,7 +36,7 @@ public function testHasWithZeroCommands() /** * Test that the command loader will return true when provided with a command "foo" */ - public function testHasWithAtLeastOneCommand() + public function testHasWithAtLeastOneCommand(): void { $subj = new CommandLoader($this->objectManagerMock, [ [ @@ -49,7 +51,7 @@ public function testHasWithAtLeastOneCommand() /** * Test that the command loader will throw a CommandNotFoundException when it does not have the requested command */ - public function testGetWithZeroCommands() + public function testGetWithZeroCommands(): void { $subj = new CommandLoader($this->objectManagerMock, []); @@ -61,7 +63,7 @@ public function testGetWithZeroCommands() /** * Test that the command loader returns a command when one it has is requested */ - public function testGetWithAtLeastOneCommand() + public function testGetWithAtLeastOneCommand(): void { $this->objectManagerMock ->method('create') @@ -81,7 +83,7 @@ public function testGetWithAtLeastOneCommand() /** * Test that the command loader will return an empty "names" array when it has none */ - public function testGetNamesWithZeroCommands() + public function testGetNamesWithZeroCommands(): void { $subj = new CommandLoader($this->objectManagerMock, []); @@ -91,7 +93,7 @@ public function testGetNamesWithZeroCommands() /** * Test that the command loader returns an array of its command names when `getNames` is called */ - public function testGetNames() + public function testGetNames(): void { $subj = new CommandLoader($this->objectManagerMock, [ [ diff --git a/lib/internal/Magento/Framework/Console/Cli.php b/lib/internal/Magento/Framework/Console/Cli.php index 7e2be244819ad..14919a60abbfb 100644 --- a/lib/internal/Magento/Framework/Console/Cli.php +++ b/lib/internal/Magento/Framework/Console/Cli.php @@ -7,6 +7,7 @@ namespace Magento\Framework\Console; +use Laminas\ServiceManager\ServiceManager; use Magento\Framework\App\Bootstrap; use Magento\Framework\App\DeploymentConfig; use Magento\Framework\App\Filesystem\DirectoryList; @@ -39,16 +40,18 @@ class Cli extends Console\Application /** * Name of input option. */ - const INPUT_KEY_BOOTSTRAP = 'bootstrap'; + public const INPUT_KEY_BOOTSTRAP = 'bootstrap'; /**#@+ * Cli exit codes. */ - const RETURN_SUCCESS = 0; - const RETURN_FAILURE = 1; + public const RETURN_SUCCESS = 0; + public const RETURN_FAILURE = 1; /**#@-*/ - /**#@-*/ + /** + * @var ServiceManager + */ private $serviceManager; /** @@ -59,8 +62,6 @@ class Cli extends Console\Application private $initException; /** - * Object Manager. - * * @var ObjectManagerInterface */ private $objectManager; diff --git a/lib/internal/Magento/Framework/Console/CommandLoader.php b/lib/internal/Magento/Framework/Console/CommandLoader.php index a79b32ec997c7..c8f25aeaa6f82 100644 --- a/lib/internal/Magento/Framework/Console/CommandLoader.php +++ b/lib/internal/Magento/Framework/Console/CommandLoader.php @@ -9,6 +9,7 @@ namespace Magento\Framework\Console; use Magento\Framework\ObjectManagerInterface; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\CommandLoader\CommandLoaderInterface; use Symfony\Component\Console\Exception\CommandNotFoundException; @@ -17,15 +18,14 @@ */ class CommandLoader implements CommandLoaderInterface { - /** * List of commands in the format [ 'command:name' => 'Fully\Qualified\ClassName' ] * @var array */ - private $commands; + private array $commands; /** @var ObjectManagerInterface */ - private $objectManager; + private ObjectManagerInterface $objectManager; /** * @param ObjectManagerInterface $objectManager @@ -43,10 +43,10 @@ public function __construct(ObjectManagerInterface $objectManager, array $comman * If the command name is not configured, throw a CommandNotFoundException. * * @param string $name - * @return \Symfony\Component\Console\Command\Command + * @return Command * @throws CommandNotFoundException */ - public function get($name): \Symfony\Component\Console\Command\Command + public function get(string $name): Command { if ($this->has($name)) { return $this->objectManager->create($this->commands[$name]); @@ -60,7 +60,7 @@ public function get($name): \Symfony\Component\Console\Command\Command * @param string $name * @return bool */ - public function has($name): bool + public function has(string $name): bool { return isset($this->commands[$name]); } diff --git a/lib/internal/Magento/Framework/Console/CommandLoader/Aggregate.php b/lib/internal/Magento/Framework/Console/CommandLoader/Aggregate.php index 810bed39dfb81..20ab2ef86061c 100644 --- a/lib/internal/Magento/Framework/Console/CommandLoader/Aggregate.php +++ b/lib/internal/Magento/Framework/Console/CommandLoader/Aggregate.php @@ -8,6 +8,7 @@ namespace Magento\Framework\Console\CommandLoader; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\CommandLoader\CommandLoaderInterface; use Symfony\Component\Console\Exception\CommandNotFoundException; @@ -17,7 +18,7 @@ class Aggregate implements CommandLoaderInterface { /** @var CommandLoaderInterface[] */ - private $commandLoaders; + private array $commandLoaders; /** * @param array $commandLoaders @@ -33,10 +34,10 @@ public function __construct(array $commandLoaders = []) * If $name does not refer to a command, throw a CommandNotFoundException. * * @param string $name - * @return \Symfony\Component\Console\Command\Command + * @return Command * @throws CommandNotFoundException */ - public function get($name): \Symfony\Component\Console\Command\Command + public function get(string $name): Command { foreach ($this->commandLoaders as $commandLoader) { if ($commandLoader->has($name)) { @@ -53,7 +54,7 @@ public function get($name): \Symfony\Component\Console\Command\Command * @param string $name * @return bool */ - public function has($name): bool + public function has(string $name): bool { foreach ($this->commandLoaders as $commandLoader) { if ($commandLoader->has($name)) { @@ -71,7 +72,7 @@ public function has($name): bool */ public function getNames(): array { - return array_merge([], ...array_map(function (CommandLoaderInterface $commandLoader) { + return array_merge([], ...array_map(static function (CommandLoaderInterface $commandLoader) { return $commandLoader->getNames(); }, $this->commandLoaders)); } diff --git a/setup/src/Magento/Setup/Console/Command/AdminUserCreateCommand.php b/setup/src/Magento/Setup/Console/Command/AdminUserCreateCommand.php index 82d4b5faf2c7b..cc9f8bbb0a988 100644 --- a/setup/src/Magento/Setup/Console/Command/AdminUserCreateCommand.php +++ b/setup/src/Magento/Setup/Console/Command/AdminUserCreateCommand.php @@ -21,7 +21,7 @@ */ class AdminUserCreateCommand extends AbstractSetupCommand { - const NAME = 'admin:user:create'; + public const NAME = 'admin:user:create'; /** * @var InstallerFactory */ diff --git a/setup/src/Magento/Setup/Console/Command/BackupCommand.php b/setup/src/Magento/Setup/Console/Command/BackupCommand.php index f065668fb946c..e68a6e664ed03 100644 --- a/setup/src/Magento/Setup/Console/Command/BackupCommand.php +++ b/setup/src/Magento/Setup/Console/Command/BackupCommand.php @@ -26,14 +26,12 @@ class BackupCommand extends AbstractSetupCommand /** * Name of input options */ - const INPUT_KEY_CODE = 'code'; - const INPUT_KEY_MEDIA = 'media'; - const INPUT_KEY_DB = 'db'; - const NAME = 'setup:backup'; + public const INPUT_KEY_CODE = 'code'; + public const INPUT_KEY_MEDIA = 'media'; + public const INPUT_KEY_DB = 'db'; + public const NAME = 'setup:backup'; /** - * Object Manager - * * @var ObjectManagerInterface */ private $objectManager; @@ -82,7 +80,7 @@ public function __construct( } /** - * {@inheritdoc} + * @inheritdoc */ protected function configure() { @@ -113,7 +111,7 @@ protected function configure() } /** - * {@inheritdoc} + * @inheritdoc */ protected function execute(InputInterface $input, OutputInterface $output) { diff --git a/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php b/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php index 44978b357d65f..a4d4909661fa2 100644 --- a/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php @@ -16,7 +16,7 @@ class ConfigSetCommand extends AbstractSetupCommand { - const NAME = 'setup:config:set'; + public const NAME = 'setup:config:set'; /** * @var ConfigModel */ @@ -31,6 +31,7 @@ class ConfigSetCommand extends AbstractSetupCommand /** * Existing deployment config + * @var DeploymentConfig */ private $deploymentConfig; diff --git a/setup/src/Magento/Setup/Console/Command/DbDataUpgradeCommand.php b/setup/src/Magento/Setup/Console/Command/DbDataUpgradeCommand.php index 035573d51bc46..be07923cc7734 100644 --- a/setup/src/Magento/Setup/Console/Command/DbDataUpgradeCommand.php +++ b/setup/src/Magento/Setup/Console/Command/DbDataUpgradeCommand.php @@ -17,7 +17,7 @@ */ class DbDataUpgradeCommand extends AbstractSetupCommand { - const NAME = 'setup:db-data:upgrade'; + public const NAME = 'setup:db-data:upgrade'; /** * Factory to create installer * @@ -57,7 +57,7 @@ protected function configure() } /** - * {@inheritdoc} + * @inheritdoc */ protected function execute(InputInterface $input, OutputInterface $output) { diff --git a/setup/src/Magento/Setup/Console/Command/DbSchemaUpgradeCommand.php b/setup/src/Magento/Setup/Console/Command/DbSchemaUpgradeCommand.php index 06e038170640f..d9cb527e9d51b 100644 --- a/setup/src/Magento/Setup/Console/Command/DbSchemaUpgradeCommand.php +++ b/setup/src/Magento/Setup/Console/Command/DbSchemaUpgradeCommand.php @@ -18,7 +18,7 @@ */ class DbSchemaUpgradeCommand extends AbstractSetupCommand { - const NAME = 'setup:db-schema:upgrade'; + public const NAME = 'setup:db-schema:upgrade'; /** * Factory to create installer. * @@ -71,7 +71,7 @@ protected function configure() } /** - * {@inheritdoc} + * @inheritdoc */ protected function execute(InputInterface $input, OutputInterface $output) { diff --git a/setup/src/Magento/Setup/Console/Command/DbStatusCommand.php b/setup/src/Magento/Setup/Console/Command/DbStatusCommand.php index eeb02d532ab93..6581ec51d9f4b 100644 --- a/setup/src/Magento/Setup/Console/Command/DbStatusCommand.php +++ b/setup/src/Magento/Setup/Console/Command/DbStatusCommand.php @@ -24,12 +24,10 @@ class DbStatusCommand extends AbstractSetupCommand /** * Code for error when application upgrade is required. */ - const EXIT_CODE_UPGRADE_REQUIRED = 2; - const NAME = 'setup:db:status'; + public const EXIT_CODE_UPGRADE_REQUIRED = 2; + public const NAME = 'setup:db:status'; /** - * Object manager provider - * * @var ObjectManagerProvider */ private $objectManagerProvider; @@ -70,7 +68,7 @@ public function __construct(ObjectManagerProvider $objectManagerProvider, Deploy } /** - * {@inheritdoc} + * @inheritdoc */ protected function configure() { @@ -80,7 +78,7 @@ protected function configure() } /** - * {@inheritdoc} + * @inheritdoc */ protected function execute(InputInterface $input, OutputInterface $output) { diff --git a/setup/src/Magento/Setup/Console/Command/DependenciesShowFrameworkCommand.php b/setup/src/Magento/Setup/Console/Command/DependenciesShowFrameworkCommand.php index 6d4a6389ca42e..501cef70768a3 100644 --- a/setup/src/Magento/Setup/Console/Command/DependenciesShowFrameworkCommand.php +++ b/setup/src/Magento/Setup/Console/Command/DependenciesShowFrameworkCommand.php @@ -16,7 +16,7 @@ */ class DependenciesShowFrameworkCommand extends AbstractDependenciesCommand { - const NAME = 'info:dependencies:show-framework'; + public const NAME = 'info:dependencies:show-framework'; /** * @var ComponentRegistrarInterface */ @@ -35,7 +35,7 @@ public function __construct(ComponentRegistrarInterface $registrar, ObjectManage } /** - * {@inheritdoc} + * @inheritdoc */ protected function configure() { diff --git a/setup/src/Magento/Setup/Console/Command/DependenciesShowModulesCircularCommand.php b/setup/src/Magento/Setup/Console/Command/DependenciesShowModulesCircularCommand.php index 3323ebaa5cd09..972cf5ee39a87 100644 --- a/setup/src/Magento/Setup/Console/Command/DependenciesShowModulesCircularCommand.php +++ b/setup/src/Magento/Setup/Console/Command/DependenciesShowModulesCircularCommand.php @@ -14,10 +14,10 @@ */ class DependenciesShowModulesCircularCommand extends AbstractDependenciesCommand { - const NAME = 'info:dependencies:show-modules-circular'; + public const NAME = 'info:dependencies:show-modules-circular'; /** - * {@inheritdoc} + * @inheritdoc */ protected function configure() { diff --git a/setup/src/Magento/Setup/Console/Command/DependenciesShowModulesCommand.php b/setup/src/Magento/Setup/Console/Command/DependenciesShowModulesCommand.php index d087ad05e4f20..1ba644406b14d 100644 --- a/setup/src/Magento/Setup/Console/Command/DependenciesShowModulesCommand.php +++ b/setup/src/Magento/Setup/Console/Command/DependenciesShowModulesCommand.php @@ -14,10 +14,10 @@ */ class DependenciesShowModulesCommand extends AbstractDependenciesCommand { - const NAME = 'info:dependencies:show-modules'; + public const NAME = 'info:dependencies:show-modules'; /** - * {@inheritdoc} + * @inheritdoc */ protected function configure() { diff --git a/setup/src/Magento/Setup/Console/Command/DeployStaticContentCommand.php b/setup/src/Magento/Setup/Console/Command/DeployStaticContentCommand.php index 9e281ce4bf829..19bccc5cc183c 100644 --- a/setup/src/Magento/Setup/Console/Command/DeployStaticContentCommand.php +++ b/setup/src/Magento/Setup/Console/Command/DeployStaticContentCommand.php @@ -31,8 +31,8 @@ class DeployStaticContentCommand extends Command /** * Default language value. Always used for adminhtml, fallback if no frontend locale is supplied. */ - const DEFAULT_LANGUAGE_VALUE = 'en_US'; - const NAME = 'setup:static-content:deploy'; + public const DEFAULT_LANGUAGE_VALUE = 'en_US'; + public const NAME = 'setup:static-content:deploy'; /** * @var InputValidator diff --git a/setup/src/Magento/Setup/Console/Command/I18nCollectPhrasesCommand.php b/setup/src/Magento/Setup/Console/Command/I18nCollectPhrasesCommand.php index e3627cf78ef27..4516b9f764603 100644 --- a/setup/src/Magento/Setup/Console/Command/I18nCollectPhrasesCommand.php +++ b/setup/src/Magento/Setup/Console/Command/I18nCollectPhrasesCommand.php @@ -20,16 +20,16 @@ class I18nCollectPhrasesCommand extends Command /**#@+ * Keys and shortcuts for input arguments and options */ - const INPUT_KEY_DIRECTORY = 'directory'; - const INPUT_KEY_OUTPUT = 'output'; - const SHORTCUT_KEY_OUTPUT = 'o'; - const INPUT_KEY_MAGENTO = 'magento'; - const SHORTCUT_KEY_MAGENTO = 'm'; - const NAME = 'i18n:collect-phrases'; + public const INPUT_KEY_DIRECTORY = 'directory'; + public const INPUT_KEY_OUTPUT = 'output'; + public const SHORTCUT_KEY_OUTPUT = 'o'; + public const INPUT_KEY_MAGENTO = 'magento'; + public const SHORTCUT_KEY_MAGENTO = 'm'; + public const NAME = 'i18n:collect-phrases'; /**#@- */ /** - * {@inheritdoc} + * @inheritdoc */ protected function configure() { @@ -58,7 +58,7 @@ protected function configure() } /** - * {@inheritdoc} + * @inheritdoc */ protected function execute(InputInterface $input, OutputInterface $output) { diff --git a/setup/src/Magento/Setup/Console/Command/I18nPackCommand.php b/setup/src/Magento/Setup/Console/Command/I18nPackCommand.php index e3cf86bebef46..56134151617c3 100644 --- a/setup/src/Magento/Setup/Console/Command/I18nPackCommand.php +++ b/setup/src/Magento/Setup/Console/Command/I18nPackCommand.php @@ -20,25 +20,25 @@ class I18nPackCommand extends Command /**#@+ * Keys and shortcuts for input arguments and options */ - const INPUT_KEY_SOURCE = 'source'; - const INPUT_KEY_LOCALE = 'locale'; - const INPUT_KEY_MODE = 'mode'; - const INPUT_KEY_ALLOW_DUPLICATES = 'allow-duplicates'; + public const INPUT_KEY_SOURCE = 'source'; + public const INPUT_KEY_LOCALE = 'locale'; + public const INPUT_KEY_MODE = 'mode'; + public const INPUT_KEY_ALLOW_DUPLICATES = 'allow-duplicates'; /**#@-*/ /** * 'replace' mode value */ - const MODE_REPLACE = 'replace'; + public const MODE_REPLACE = 'replace'; /** * 'merge' mode value */ - const MODE_MERGE = 'merge'; - const NAME = 'i18n:pack'; + public const MODE_MERGE = 'merge'; + public const NAME = 'i18n:pack'; /** - * {@inheritdoc} + * @inheritdoc */ protected function configure() { @@ -74,7 +74,7 @@ protected function configure() } /** - * {@inheritdoc} + * @inheritdoc * @throws \InvalidArgumentException */ protected function execute(InputInterface $input, OutputInterface $output) diff --git a/setup/src/Magento/Setup/Console/Command/InfoAdminUriCommand.php b/setup/src/Magento/Setup/Console/Command/InfoAdminUriCommand.php index a8d710a7f060d..ecbe3c7b5220f 100644 --- a/setup/src/Magento/Setup/Console/Command/InfoAdminUriCommand.php +++ b/setup/src/Magento/Setup/Console/Command/InfoAdminUriCommand.php @@ -13,7 +13,7 @@ class InfoAdminUriCommand extends Command { - const NAME = 'info:adminuri'; + public const NAME = 'info:adminuri'; /** * @var \Magento\Framework\App\DeploymentConfig */ @@ -45,7 +45,7 @@ protected function configure() } /** - * {@inheritdoc} + * @inheritdoc */ protected function execute(InputInterface $input, OutputInterface $output) { diff --git a/setup/src/Magento/Setup/Console/Command/InfoBackupsListCommand.php b/setup/src/Magento/Setup/Console/Command/InfoBackupsListCommand.php index 07f8f0900f82a..7e5ad65c3c5ec 100644 --- a/setup/src/Magento/Setup/Console/Command/InfoBackupsListCommand.php +++ b/setup/src/Magento/Setup/Console/Command/InfoBackupsListCommand.php @@ -21,10 +21,8 @@ */ class InfoBackupsListCommand extends Command { - const NAME = 'info:backups:list'; + public const NAME = 'info:backups:list'; /** - * File - * * @var File */ private $file; @@ -58,7 +56,7 @@ public function __construct( } /** - * {@inheritdoc} + * @inheritdoc */ protected function configure() { @@ -69,7 +67,7 @@ protected function configure() } /** - * {@inheritdoc} + * @inheritdoc */ protected function execute(InputInterface $input, OutputInterface $output) { diff --git a/setup/src/Magento/Setup/Console/Command/InfoCurrencyListCommand.php b/setup/src/Magento/Setup/Console/Command/InfoCurrencyListCommand.php index c2dbe0ba0aaf9..8eda22f00115a 100644 --- a/setup/src/Magento/Setup/Console/Command/InfoCurrencyListCommand.php +++ b/setup/src/Magento/Setup/Console/Command/InfoCurrencyListCommand.php @@ -18,7 +18,7 @@ */ class InfoCurrencyListCommand extends Command { - const NAME = 'info:currency:list'; + public const NAME = 'info:currency:list'; /** * List model provides lists of available options for currency, language locales, timezones * @@ -43,7 +43,7 @@ public function __construct(Lists $lists, TableFactory $tableHelperFactory = nul } /** - * {@inheritdoc} + * @inheritdoc */ protected function configure() { @@ -54,7 +54,7 @@ protected function configure() } /** - * {@inheritdoc} + * @inheritdoc */ protected function execute(InputInterface $input, OutputInterface $output) { diff --git a/setup/src/Magento/Setup/Console/Command/InfoLanguageListCommand.php b/setup/src/Magento/Setup/Console/Command/InfoLanguageListCommand.php index 34f6171e04999..d44601b52683b 100644 --- a/setup/src/Magento/Setup/Console/Command/InfoLanguageListCommand.php +++ b/setup/src/Magento/Setup/Console/Command/InfoLanguageListCommand.php @@ -18,7 +18,7 @@ */ class InfoLanguageListCommand extends Command { - const NAME = 'info:language:list'; + public const NAME = 'info:language:list'; /** * List model provides lists of available options for currency, language locales, timezones * @@ -43,7 +43,7 @@ public function __construct(Lists $lists, TableFactory $tableHelperFactory = nul } /** - * {@inheritdoc} + * @inheritdoc */ protected function configure() { @@ -54,7 +54,7 @@ protected function configure() } /** - * {@inheritdoc} + * @inheritdoc */ protected function execute(InputInterface $input, OutputInterface $output) { diff --git a/setup/src/Magento/Setup/Console/Command/InfoTimezoneListCommand.php b/setup/src/Magento/Setup/Console/Command/InfoTimezoneListCommand.php index 84f2455675ab4..b313840bfff47 100644 --- a/setup/src/Magento/Setup/Console/Command/InfoTimezoneListCommand.php +++ b/setup/src/Magento/Setup/Console/Command/InfoTimezoneListCommand.php @@ -18,7 +18,7 @@ */ class InfoTimezoneListCommand extends Command { - const NAME = 'info:timezone:list'; + public const NAME = 'info:timezone:list'; /** * List model provides lists of available options for currency, language locales, timezones * @@ -43,7 +43,7 @@ public function __construct(Lists $lists, TableFactory $tableHelperFactory = nul } /** - * {@inheritdoc} + * @inheritdoc */ protected function configure() { @@ -54,7 +54,7 @@ protected function configure() } /** - * {@inheritdoc} + * @inheritdoc */ protected function execute(InputInterface $input, OutputInterface $output) { diff --git a/setup/src/Magento/Setup/Console/Command/InstallStoreConfigurationCommand.php b/setup/src/Magento/Setup/Console/Command/InstallStoreConfigurationCommand.php index 3e398238f4979..3e094fba74294 100644 --- a/setup/src/Magento/Setup/Console/Command/InstallStoreConfigurationCommand.php +++ b/setup/src/Magento/Setup/Console/Command/InstallStoreConfigurationCommand.php @@ -14,8 +14,6 @@ use Symfony\Component\Console\Output\OutputInterface; use Magento\Setup\Model\StoreConfigurationDataMapper; use Magento\Setup\Model\ObjectManagerProvider; -use Magento\Framework\ObjectManagerInterface; -use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Validator\Locale as LocaleValidator; use Magento\Framework\Validator\Timezone as TimezoneValidator; use Magento\Framework\Validator\Currency as CurrencyValidator; @@ -26,27 +24,17 @@ */ class InstallStoreConfigurationCommand extends AbstractSetupCommand { - const NAME = 'setup:store-config:set'; + public const NAME = 'setup:store-config:set'; /** * @var InstallerFactory */ private $installerFactory; /** - * Deployment configuration - * * @var DeploymentConfig */ private $deploymentConfig; - /** - * Object Manager - * - * @var ObjectManagerInterface - * @deprecated 2.2.0 - */ - private $objectManager; - /** * @var LocaleValidator */ @@ -72,11 +60,12 @@ class InstallStoreConfigurationCommand extends AbstractSetupCommand * * @param InstallerFactory $installerFactory * @param DeploymentConfig $deploymentConfig - * @param ObjectManagerProvider $objectManagerProvider - * @param LocaleValidator $localeValidator, - * @param TimezoneValidator $timezoneValidator, - * @param CurrencyValidator $currencyValidator, + * @param ObjectManagerProvider $objectManagerProvider Deprecated since not used anymore + * @param LocaleValidator $localeValidator + * @param TimezoneValidator $timezoneValidator + * @param CurrencyValidator $currencyValidator * @param UrlValidator $urlValidator + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function __construct( InstallerFactory $installerFactory, @@ -89,7 +78,6 @@ public function __construct( ) { $this->installerFactory = $installerFactory; $this->deploymentConfig = $deploymentConfig; - $this->objectManager = $objectManagerProvider->get(); $this->localeValidator = $localeValidator; $this->timezoneValidator = $timezoneValidator; $this->currencyValidator = $currencyValidator; @@ -98,7 +86,7 @@ public function __construct( } /** - * {@inheritdoc} + * @inheritdoc */ protected function configure() { @@ -109,7 +97,7 @@ protected function configure() } /** - * {@inheritdoc} + * @inheritdoc */ protected function execute(InputInterface $input, OutputInterface $output) { @@ -311,9 +299,9 @@ private function validateBinaryValue($value, $key) /** * Validate codes for languages, currencies or timezones * - * @param LocaleValidator|TimezoneValidator|CurrencyValidator $lists - * @param string $code - * @param string $type + * @param LocaleValidator|TimezoneValidator|CurrencyValidator $lists + * @param string $code + * @param string $type * @return string */ private function validateCodes($lists, $code, $type) diff --git a/setup/src/Magento/Setup/Console/Command/ModuleConfigStatusCommand.php b/setup/src/Magento/Setup/Console/Command/ModuleConfigStatusCommand.php index ae76f66892bf1..99a1bbe244954 100644 --- a/setup/src/Magento/Setup/Console/Command/ModuleConfigStatusCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ModuleConfigStatusCommand.php @@ -23,7 +23,7 @@ */ class ModuleConfigStatusCommand extends Command { - const NAME = 'module:config:status'; + public const NAME = 'module:config:status'; /** * Deployment config reader * diff --git a/setup/src/Magento/Setup/Console/Command/ModuleDisableCommand.php b/setup/src/Magento/Setup/Console/Command/ModuleDisableCommand.php index a95e3f6bb757d..67634410bc48e 100644 --- a/setup/src/Magento/Setup/Console/Command/ModuleDisableCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ModuleDisableCommand.php @@ -10,10 +10,10 @@ */ class ModuleDisableCommand extends AbstractModuleManageCommand { - const NAME = 'module:disable'; + public const NAME = 'module:disable'; /** - * {@inheritdoc} + * @inheritdoc */ protected function configure() { diff --git a/setup/src/Magento/Setup/Console/Command/ModuleEnableCommand.php b/setup/src/Magento/Setup/Console/Command/ModuleEnableCommand.php index 47588567fe1aa..ba784a17b776d 100644 --- a/setup/src/Magento/Setup/Console/Command/ModuleEnableCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ModuleEnableCommand.php @@ -10,10 +10,10 @@ */ class ModuleEnableCommand extends AbstractModuleManageCommand { - const NAME = 'module:enable'; + public const NAME = 'module:enable'; /** - * {@inheritdoc} + * @inheritdoc */ protected function configure() { diff --git a/setup/src/Magento/Setup/Console/Command/ModuleStatusCommand.php b/setup/src/Magento/Setup/Console/Command/ModuleStatusCommand.php index 403c0307b087b..700767dd07c81 100644 --- a/setup/src/Magento/Setup/Console/Command/ModuleStatusCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ModuleStatusCommand.php @@ -21,7 +21,7 @@ */ class ModuleStatusCommand extends AbstractSetupCommand { - const NAME = 'module:status'; + public const NAME = 'module:status'; /** * @var ObjectManagerProvider */ diff --git a/setup/src/Magento/Setup/Console/Command/ModuleUninstallCommand.php b/setup/src/Magento/Setup/Console/Command/ModuleUninstallCommand.php index cf4d703b6c3fd..479b7329d98b4 100644 --- a/setup/src/Magento/Setup/Console/Command/ModuleUninstallCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ModuleUninstallCommand.php @@ -36,12 +36,12 @@ class ModuleUninstallCommand extends AbstractModuleCommand /** * Names of input options */ - const INPUT_KEY_REMOVE_DATA = 'remove-data'; - const INPUT_KEY_BACKUP_CODE = 'backup-code'; - const INPUT_KEY_BACKUP_MEDIA = 'backup-media'; - const INPUT_KEY_BACKUP_DB = 'backup-db'; - const INPUT_KEY_NON_COMPOSER_MODULE = 'non-composer'; - const NAME = 'module:uninstall'; + public const INPUT_KEY_REMOVE_DATA = 'remove-data'; + public const INPUT_KEY_BACKUP_CODE = 'backup-code'; + public const INPUT_KEY_BACKUP_MEDIA = 'backup-media'; + public const INPUT_KEY_BACKUP_DB = 'backup-db'; + public const INPUT_KEY_NON_COMPOSER_MODULE = 'non-composer'; + public const NAME = 'module:uninstall'; /** * Deployment Configuration @@ -51,8 +51,6 @@ class ModuleUninstallCommand extends AbstractModuleCommand private $deploymentConfig; /** - * Full module list - * * @var FullModuleList */ private $fullModuleList; @@ -86,22 +84,16 @@ class ModuleUninstallCommand extends AbstractModuleCommand private $composer; /** - * BackupRollback factory - * * @var BackupRollbackFactory */ private $backupRollbackFactory; /** - * Module Uninstaller - * * @var ModuleUninstaller */ private $moduleUninstaller; /** - * Module Registry uninstaller - * * @var ModuleRegistryUninstaller */ private $moduleRegistryUninstaller; @@ -157,6 +149,8 @@ public function __construct( } /** + * Returns patch applier object + * * @return PatchApplier */ private function getPatchApplier() @@ -170,7 +164,7 @@ private function getPatchApplier() } /** - * {@inheritdoc} + * @inheritdoc */ protected function configure() { @@ -213,7 +207,7 @@ protected function configure() } /** - * {@inheritdoc} + * @inheritdoc */ protected function isModuleRequired() { @@ -221,7 +215,7 @@ protected function isModuleRequired() } /** - * {@inheritdoc} + * @inheritdoc * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ diff --git a/setup/src/Magento/Setup/Console/Command/RollbackCommand.php b/setup/src/Magento/Setup/Console/Command/RollbackCommand.php index 1deaf642b93d4..f1f2d1c5eb8b0 100644 --- a/setup/src/Magento/Setup/Console/Command/RollbackCommand.php +++ b/setup/src/Magento/Setup/Console/Command/RollbackCommand.php @@ -27,14 +27,12 @@ class RollbackCommand extends AbstractSetupCommand /** * Name of input arguments or options */ - const INPUT_KEY_CODE_BACKUP_FILE = 'code-file'; - const INPUT_KEY_MEDIA_BACKUP_FILE = 'media-file'; - const INPUT_KEY_DB_BACKUP_FILE = 'db-file'; - const NAME = 'setup:rollback'; + public const INPUT_KEY_CODE_BACKUP_FILE = 'code-file'; + public const INPUT_KEY_MEDIA_BACKUP_FILE = 'media-file'; + public const INPUT_KEY_DB_BACKUP_FILE = 'db-file'; + public const NAME = 'setup:rollback'; /** - * Object Manager - * * @var ObjectManagerInterface */ private $objectManager; diff --git a/setup/src/Magento/Setup/Console/Command/UninstallCommand.php b/setup/src/Magento/Setup/Console/Command/UninstallCommand.php index 58a8f901fee94..50c31984cb659 100644 --- a/setup/src/Magento/Setup/Console/Command/UninstallCommand.php +++ b/setup/src/Magento/Setup/Console/Command/UninstallCommand.php @@ -14,7 +14,7 @@ class UninstallCommand extends AbstractSetupCommand { - const NAME = 'setup:uninstall'; + public const NAME = 'setup:uninstall'; /** * @var InstallerFactory */ @@ -30,7 +30,7 @@ public function __construct(InstallerFactory $installerFactory) } /** - * {@inheritdoc} + * @inheritdoc */ protected function configure() { @@ -40,7 +40,7 @@ protected function configure() } /** - * {@inheritdoc} + * @inheritdoc */ protected function execute(InputInterface $input, OutputInterface $output) { diff --git a/setup/src/Magento/Setup/Console/CommandLoader.php b/setup/src/Magento/Setup/Console/CommandLoader.php index 6142681f140fb..2a716e96bdbe2 100644 --- a/setup/src/Magento/Setup/Console/CommandLoader.php +++ b/setup/src/Magento/Setup/Console/CommandLoader.php @@ -20,17 +20,15 @@ class CommandLoader implements CommandLoaderInterface { /** - * Service Manager - * * @var ServiceManager */ - private $serviceManager; + private ServiceManager $serviceManager; /** * Array of command classes keyed by name * @var string[] */ - private $commands = [ + private array $commands = [ Command\AdminUserCreateCommand::NAME => Command\AdminUserCreateCommand::class, Command\BackupCommand::NAME => Command\BackupCommand::class, Command\ConfigSetCommand::NAME => Command\ConfigSetCommand::class, @@ -63,7 +61,6 @@ class CommandLoader implements CommandLoaderInterface ]; /** - * Constructor * * @param ServiceManager $serviceManager */ @@ -79,7 +76,7 @@ public function __construct(ServiceManager $serviceManager) * @return SymfonyCommand * @throws CommandNotFoundException */ - public function get($name): SymfonyCommand + public function get(string $name): SymfonyCommand { if ($this->has($name)) { /** @var SymfonyCommand $command */ @@ -96,7 +93,7 @@ public function get($name): SymfonyCommand * @param string $name * @return bool */ - public function has($name): bool + public function has(string $name): bool { return isset($this->commands[$name]); } diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/InstallStoreConfigurationCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/InstallStoreConfigurationCommandTest.php index 7e29c1ab90d9a..16d7ab5bf34b8 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/InstallStoreConfigurationCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/InstallStoreConfigurationCommandTest.php @@ -8,7 +8,6 @@ namespace Magento\Setup\Test\Unit\Console\Command; use Magento\Framework\App\DeploymentConfig; -use Magento\Framework\ObjectManagerInterface; use Magento\Framework\Validator\Currency as CurrencyValidator; use Magento\Framework\Validator\Locale as LocaleValidator; use Magento\Framework\Validator\Timezone as TimezoneValidator; @@ -42,11 +41,6 @@ class InstallStoreConfigurationCommandTest extends TestCase */ private $installer; - /** - * @var ObjectManagerInterface|MockObject - */ - private $objectManager; - /** * @var LocaleValidator|MockObject */ @@ -83,13 +77,7 @@ protected function setUp(): void $this->deploymentConfig = $this->createMock(DeploymentConfig::class); $this->installer = $this->createMock(Installer::class); $objectManagerProvider = $this->createMock(ObjectManagerProvider::class); - $this->objectManager = $this->getMockForAbstractClass( - ObjectManagerInterface::class, - [], - '', - false - ); - $objectManagerProvider->expects($this->once())->method('get')->willReturn($this->objectManager); + $this->command = new InstallStoreConfigurationCommand( $this->installerFactory, $this->deploymentConfig, diff --git a/setup/src/Magento/Setup/Test/Unit/Console/CommandLoaderTest.php b/setup/src/Magento/Setup/Test/Unit/Console/CommandLoaderTest.php index da7fef93f73b6..b58c92893eeff 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/CommandLoaderTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/CommandLoaderTest.php @@ -11,18 +11,19 @@ use Magento\Setup\Console\CommandLoader; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +use Symfony\Component\Console\Command\Command; class CommandLoaderTest extends TestCase { /** * @var MockObject|CommandLoader */ - private $commandLoader; + private MockObject|CommandLoader $commandLoader; /** * @var MockObject|ServiceManager */ - private $serviceManager; + private ServiceManager|MockObject $serviceManager; protected function setUp(): void { @@ -30,9 +31,9 @@ protected function setUp(): void $this->commandLoader = new CommandLoader($this->serviceManager); } - public function testServiceManagerIsUsedToInitializeCommands() + public function testServiceManagerIsUsedToInitializeCommands(): void { - $command = $this->getMockBuilder(\Symfony\Component\Console\Command\Command::class) + $command = $this->getMockBuilder(Command::class) ->disableOriginalConstructor() ->getMock(); $this->serviceManager->expects($this->once()) From f6152ed771998388988cff0c597fa97b233252ba Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Tue, 23 Apr 2024 11:41:11 +0300 Subject: [PATCH 3/4] Implement command loader Fix test failures --- .../Test/Unit/Console/CommandLoader/AggregateTest.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandLoader/AggregateTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandLoader/AggregateTest.php index 7c25c3262abe8..bc56fb3f027ed 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandLoader/AggregateTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandLoader/AggregateTest.php @@ -71,10 +71,16 @@ public function testGet(?Command $firstCmd, ?Command $secondCmd): void { $firstHas = (bool)$firstCmd; $secondHas = (bool)$secondCmd; + $this->firstMockCommandLoader->method('has')->with('foo')->willReturn($firstHas); - $this->firstMockCommandLoader->method('get')->with('foo')->willReturn($firstCmd); + if ($firstHas) { + $this->firstMockCommandLoader->method('get')->with('foo')->willReturn($firstCmd); + } + $this->secondMockCommandLoader->method('has')->with('foo')->willReturn($secondHas); - $this->secondMockCommandLoader->method('get')->with('foo')->willReturn($secondCmd); + if ($secondHas) { + $this->secondMockCommandLoader->method('get')->with('foo')->willReturn($secondCmd); + } $this->assertInstanceOf(Command::class, $this->aggregateCommandLoader->get('foo')); } From 7d4d66985ab4bbdb22b246398ea80b83019fa53c Mon Sep 17 00:00:00 2001 From: engcom-Dash Date: Fri, 8 Nov 2024 15:06:42 +0530 Subject: [PATCH 4/4] 29355: Fix static failure related to copyright tag --- .../Backend/Console/Command/MaintenanceAllowIpsCommand.php | 4 ++-- .../Backend/Console/Command/MaintenanceDisableCommand.php | 4 ++-- .../Backend/Console/Command/MaintenanceEnableCommand.php | 4 ++-- .../Backend/Console/Command/MaintenanceStatusCommand.php | 4 ++-- .../Magento/Test/Integrity/Library/DependencyTest.php | 4 ++-- .../App/Test/Unit/Console/CommandLoader/AggregateTest.php | 7 ++++--- .../Framework/App/Test/Unit/Console/CommandLoaderTest.php | 7 ++++--- lib/internal/Magento/Framework/Console/Cli.php | 4 ++-- lib/internal/Magento/Framework/Console/CommandLoader.php | 4 ++-- .../Magento/Framework/Console/CommandLoader/Aggregate.php | 4 ++-- .../Setup/Console/Command/AdminUserCreateCommand.php | 4 ++-- setup/src/Magento/Setup/Console/Command/BackupCommand.php | 4 ++-- .../src/Magento/Setup/Console/Command/ConfigSetCommand.php | 4 ++-- .../Magento/Setup/Console/Command/DbDataUpgradeCommand.php | 4 ++-- .../Setup/Console/Command/DbSchemaUpgradeCommand.php | 4 ++-- .../src/Magento/Setup/Console/Command/DbStatusCommand.php | 4 ++-- .../Console/Command/DependenciesShowFrameworkCommand.php | 4 ++-- .../Command/DependenciesShowModulesCircularCommand.php | 4 ++-- .../Console/Command/DependenciesShowModulesCommand.php | 4 ++-- .../Setup/Console/Command/DeployStaticContentCommand.php | 4 ++-- .../Setup/Console/Command/GenerateFixturesCommand.php | 4 ++-- .../Setup/Console/Command/I18nCollectPhrasesCommand.php | 4 ++-- .../src/Magento/Setup/Console/Command/I18nPackCommand.php | 4 ++-- .../Magento/Setup/Console/Command/InfoAdminUriCommand.php | 4 ++-- .../Setup/Console/Command/InfoBackupsListCommand.php | 4 ++-- .../Setup/Console/Command/InfoCurrencyListCommand.php | 4 ++-- .../Setup/Console/Command/InfoLanguageListCommand.php | 4 ++-- .../Setup/Console/Command/InfoTimezoneListCommand.php | 4 ++-- setup/src/Magento/Setup/Console/Command/InstallCommand.php | 4 ++-- .../Console/Command/InstallStoreConfigurationCommand.php | 4 ++-- .../Setup/Console/Command/ModuleConfigStatusCommand.php | 4 ++-- .../Magento/Setup/Console/Command/ModuleDisableCommand.php | 4 ++-- .../Magento/Setup/Console/Command/ModuleEnableCommand.php | 4 ++-- .../Magento/Setup/Console/Command/ModuleStatusCommand.php | 5 ++--- .../Setup/Console/Command/ModuleUninstallCommand.php | 4 ++-- .../src/Magento/Setup/Console/Command/RollbackCommand.php | 4 ++-- .../src/Magento/Setup/Console/Command/UninstallCommand.php | 4 ++-- setup/src/Magento/Setup/Console/Command/UpgradeCommand.php | 4 ++-- setup/src/Magento/Setup/Console/CommandLoader.php | 6 +++--- .../Command/InstallStoreConfigurationCommandTest.php | 4 ++-- .../Magento/Setup/Test/Unit/Console/CommandLoaderTest.php | 4 ++-- 41 files changed, 87 insertions(+), 86 deletions(-) diff --git a/app/code/Magento/Backend/Console/Command/MaintenanceAllowIpsCommand.php b/app/code/Magento/Backend/Console/Command/MaintenanceAllowIpsCommand.php index e6d3db449621e..8cddc014b8855 100644 --- a/app/code/Magento/Backend/Console/Command/MaintenanceAllowIpsCommand.php +++ b/app/code/Magento/Backend/Console/Command/MaintenanceAllowIpsCommand.php @@ -1,7 +1,7 @@