-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Adds module:config:status command which checks if the module config i… #22733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
magento-engcom-team
merged 2 commits into
magento:2.3-develop
from
hostep:adds-module-config-status-command
Jul 11, 2019
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
setup/src/Magento/Setup/Console/Command/ModuleConfigStatusCommand.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\Setup\Console\Command; | ||
|
||
use Magento\Framework\App\DeploymentConfig\Reader as ConfigReader; | ||
use Magento\Framework\Config\ConfigOptionsListConstants; | ||
use Magento\Framework\Config\File\ConfigFilePool; | ||
use Magento\Framework\Console\Cli; | ||
use Magento\Framework\Setup\ConsoleLogger; | ||
use Magento\Setup\Model\InstallerFactory; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Command to check if the modules config in app/etc/config.php matches with how Magento interprets it | ||
*/ | ||
class ModuleConfigStatusCommand extends Command | ||
{ | ||
/** | ||
* Deployment config reader | ||
* | ||
* @var ConfigReader | ||
*/ | ||
private $configReader; | ||
|
||
/** | ||
* Installer service factory. | ||
* | ||
* @var InstallerFactory | ||
*/ | ||
private $installerFactory; | ||
|
||
/** | ||
* @param ConfigReader $configReader | ||
* @param InstallerFactory $installerFactory | ||
*/ | ||
public function __construct( | ||
ConfigReader $configReader, | ||
InstallerFactory $installerFactory | ||
) { | ||
$this->configReader = $configReader; | ||
$this->installerFactory = $installerFactory; | ||
|
||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('module:config:status') | ||
->setDescription( | ||
'Checks the modules configuration in the \'app/etc/config.php\' file ' | ||
. 'and reports if they are up to date or not' | ||
); | ||
|
||
parent::configure(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
try { | ||
// the config as currently in app/etc/config.php | ||
$currentConfig = $this->configReader->load(ConfigFilePool::APP_CONFIG); | ||
if (!array_key_exists(ConfigOptionsListConstants::KEY_MODULES, $currentConfig)) { | ||
// phpcs:ignore Magento2.Exceptions.DirectThrow | ||
throw new \Exception('Can\'t find the modules configuration in the \'app/etc/config.php\' file.'); | ||
} | ||
|
||
$currentModuleConfig = $currentConfig[ConfigOptionsListConstants::KEY_MODULES]; | ||
|
||
$installer = $this->installerFactory->create(new ConsoleLogger($output)); | ||
|
||
// the module config as Magento calculated it | ||
$correctModuleConfig = $installer->getModulesConfig(); | ||
|
||
if ($currentModuleConfig !== $correctModuleConfig) { | ||
// phpcs:ignore Magento2.Exceptions.DirectThrow | ||
throw new \Exception( | ||
'The modules configuration in the \'app/etc/config.php\' file is outdated. ' | ||
. 'Run \'setup:upgrade\' to fix it.' | ||
); | ||
} | ||
|
||
$output->writeln( | ||
'<info>The modules configuration is up to date.</info>' | ||
); | ||
// phpcs:disable Magento2.Exceptions.ThrowCatch | ||
} catch (\Exception $e) { | ||
$output->writeln('<error>' . $e->getMessage() . '</error>'); | ||
|
||
return Cli::RETURN_FAILURE; | ||
} | ||
|
||
return Cli::RETURN_SUCCESS; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
setup/src/Magento/Setup/Test/Unit/Console/Command/ModuleConfigStatusCommandTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\Setup\Test\Unit\Console\Command; | ||
|
||
use Magento\Framework\Config\ConfigOptionsListConstants; | ||
use Magento\Setup\Console\Command\ModuleConfigStatusCommand; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
||
/** | ||
* Tests for module config status command. | ||
*/ | ||
class ModuleConfigStatusCommandTest extends TestCase | ||
{ | ||
/** | ||
* @param array $currentConfig | ||
* @param array $correctConfig | ||
* @param string $expectedOutput | ||
* @dataProvider executeDataProvider | ||
*/ | ||
public function testExecute(array $currentConfig, array $correctConfig, string $expectedOutput) | ||
{ | ||
$configReader = $this->createMock(\Magento\Framework\App\DeploymentConfig\Reader::class); | ||
$configReader->expects($this->once()) | ||
->method('load') | ||
->willReturn([ConfigOptionsListConstants::KEY_MODULES => $currentConfig]); | ||
|
||
$installer = $this->createMock(\Magento\Setup\Model\Installer::class); | ||
$installer->expects($this->once()) | ||
->method('getModulesConfig') | ||
->willReturn($correctConfig); | ||
|
||
$installerFactory = $this->createMock(\Magento\Setup\Model\InstallerFactory::class); | ||
$installerFactory->expects($this->once()) | ||
->method('create') | ||
->willReturn($installer); | ||
|
||
$command = new ModuleConfigStatusCommand($configReader, $installerFactory); | ||
|
||
$tester = new CommandTester($command); | ||
$tester->execute([]); | ||
|
||
$this->assertEquals($expectedOutput, $tester->getDisplay()); | ||
} | ||
|
||
public function executeDataProvider() | ||
{ | ||
$successMessage = 'The modules configuration is up to date.' . PHP_EOL; | ||
$failureMessage = 'The modules configuration in the \'app/etc/config.php\' ' | ||
. 'file is outdated. Run \'setup:upgrade\' to fix it.' . PHP_EOL; | ||
|
||
return [ | ||
[ | ||
['Magento_ModuleA' => 1, 'Magento_ModuleB' => 1], | ||
['Magento_ModuleA' => 1, 'Magento_ModuleB' => 1], | ||
$successMessage, | ||
], | ||
[ | ||
['Magento_ModuleA' => 0, 'Magento_ModuleB' => 1], | ||
['Magento_ModuleA' => 0, 'Magento_ModuleB' => 1], | ||
$successMessage, | ||
], | ||
[ | ||
['Magento_ModuleA' => 1, 'Magento_ModuleB' => 1], | ||
['Magento_ModuleB' => 1, 'Magento_ModuleA' => 1], | ||
$failureMessage, | ||
], | ||
[ | ||
['Magento_ModuleA' => 0, 'Magento_ModuleB' => 1], | ||
['Magento_ModuleB' => 1, 'Magento_ModuleA' => 0], | ||
$failureMessage, | ||
], | ||
[ | ||
['Magento_ModuleA' => 1], | ||
['Magento_ModuleB' => 1, 'Magento_ModuleA' => 1], | ||
$failureMessage, | ||
], | ||
[ | ||
['Magento_ModuleA' => 1, 'Magento_ModuleB' => 1], | ||
['Magento_ModuleB' => 1], | ||
$failureMessage, | ||
], | ||
]; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.