From 8805bc07da432624236a4678258a5c6973545810 Mon Sep 17 00:00:00 2001 From: alojua Date: Sat, 25 Nov 2017 12:51:27 +0100 Subject: [PATCH 1/3] Add command "app:config:status" to check whether the config propagation is up to date. This command can be used to decide whether app:config:import execution is needed --- .../Command/App/ConfigStatusCommand.php | 64 ++++++++++++++++ .../Command/App/ConfigStatusCommandTest.php | 76 +++++++++++++++++++ app/code/Magento/Deploy/etc/di.xml | 1 + 3 files changed, 141 insertions(+) create mode 100644 app/code/Magento/Deploy/Console/Command/App/ConfigStatusCommand.php create mode 100644 app/code/Magento/Deploy/Test/Unit/Console/Command/App/ConfigStatusCommandTest.php diff --git a/app/code/Magento/Deploy/Console/Command/App/ConfigStatusCommand.php b/app/code/Magento/Deploy/Console/Command/App/ConfigStatusCommand.php new file mode 100644 index 0000000000000..57782a3be5e53 --- /dev/null +++ b/app/code/Magento/Deploy/Console/Command/App/ConfigStatusCommand.php @@ -0,0 +1,64 @@ +changeDetector = $changeDetector; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this->setName('app:config:status') + ->setDescription('Checks if config propagation requires update'); + parent::configure(); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + if ($this->changeDetector->hasChanges()) { + $output->writeln( + 'The configuration file has changed. ' . + 'Run app:config:import or setup:upgrade command to synchronize configuration.' + ); + return self::EXIT_CODE_CONFIG_IMPORT_REQUIRED; + } + $output->writeln('Configuration files are up to date.'); + return Cli::RETURN_SUCCESS; + } +} \ No newline at end of file diff --git a/app/code/Magento/Deploy/Test/Unit/Console/Command/App/ConfigStatusCommandTest.php b/app/code/Magento/Deploy/Test/Unit/Console/Command/App/ConfigStatusCommandTest.php new file mode 100644 index 0000000000000..cff4e7b4559c6 --- /dev/null +++ b/app/code/Magento/Deploy/Test/Unit/Console/Command/App/ConfigStatusCommandTest.php @@ -0,0 +1,76 @@ +changeDetector = $this->getMockBuilder(ChangeDetector::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->command = new ConfigStatusCommand($this->changeDetector); + } + + /** + * @param bool $hasChanges + * @param string $expectedMessage + * @param int $expectedCode + * + * @dataProvider executeDataProvider + */ + public function testExecute(bool $hasChanges, $expectedMessage, $expectedCode) + { + $this->changeDetector->expects($this->once()) + ->method('hasChanges') + ->will($this->returnValue($hasChanges)); + + $tester = new CommandTester($this->command); + $tester->execute([]); + + $this->assertEquals($expectedMessage, $tester->getDisplay()); + $this->assertSame($expectedCode, $tester->getStatusCode()); + } + + public function executeDataProvider() + { + return [ + 'Config is up to date' => [ + false, + 'Configuration files are up to date.' . PHP_EOL, + Cli::RETURN_SUCCESS + ], + 'Config needs update' => [ + true, + 'The configuration file has changed. ' . + 'Run app:config:import or setup:upgrade command to synchronize configuration.' . PHP_EOL, + ConfigStatusCommand::EXIT_CODE_CONFIG_IMPORT_REQUIRED, + ], + ]; + } +} \ No newline at end of file diff --git a/app/code/Magento/Deploy/etc/di.xml b/app/code/Magento/Deploy/etc/di.xml index e47fca3a6b946..ce7c84c95538a 100644 --- a/app/code/Magento/Deploy/etc/di.xml +++ b/app/code/Magento/Deploy/etc/di.xml @@ -31,6 +31,7 @@ \Magento\Deploy\Console\Command\App\ApplicationDumpCommand \Magento\Deploy\Console\Command\App\SensitiveConfigSetCommand Magento\Deploy\Console\Command\App\ConfigImportCommand + Magento\Deploy\Console\Command\App\ConfigStatusCommand From e47ec9b35325c1c1134f9340784f7e8f79c36c61 Mon Sep 17 00:00:00 2001 From: alojua Date: Sat, 25 Nov 2017 17:32:27 +0100 Subject: [PATCH 2/3] Small change on output messages --- .../Deploy/Console/Command/App/ConfigStatusCommand.php | 4 ++-- .../Test/Unit/Console/Command/App/ConfigStatusCommandTest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Deploy/Console/Command/App/ConfigStatusCommand.php b/app/code/Magento/Deploy/Console/Command/App/ConfigStatusCommand.php index 57782a3be5e53..534a54918a396 100644 --- a/app/code/Magento/Deploy/Console/Command/App/ConfigStatusCommand.php +++ b/app/code/Magento/Deploy/Console/Command/App/ConfigStatusCommand.php @@ -53,12 +53,12 @@ protected function execute(InputInterface $input, OutputInterface $output) { if ($this->changeDetector->hasChanges()) { $output->writeln( - 'The configuration file has changed. ' . + 'Config files have changed. ' . 'Run app:config:import or setup:upgrade command to synchronize configuration.' ); return self::EXIT_CODE_CONFIG_IMPORT_REQUIRED; } - $output->writeln('Configuration files are up to date.'); + $output->writeln('Config files are up to date.'); return Cli::RETURN_SUCCESS; } } \ No newline at end of file diff --git a/app/code/Magento/Deploy/Test/Unit/Console/Command/App/ConfigStatusCommandTest.php b/app/code/Magento/Deploy/Test/Unit/Console/Command/App/ConfigStatusCommandTest.php index cff4e7b4559c6..3e400a28537e3 100644 --- a/app/code/Magento/Deploy/Test/Unit/Console/Command/App/ConfigStatusCommandTest.php +++ b/app/code/Magento/Deploy/Test/Unit/Console/Command/App/ConfigStatusCommandTest.php @@ -62,12 +62,12 @@ public function executeDataProvider() return [ 'Config is up to date' => [ false, - 'Configuration files are up to date.' . PHP_EOL, + 'Config files are up to date.' . PHP_EOL, Cli::RETURN_SUCCESS ], 'Config needs update' => [ true, - 'The configuration file has changed. ' . + 'Config files have changed. ' . 'Run app:config:import or setup:upgrade command to synchronize configuration.' . PHP_EOL, ConfigStatusCommand::EXIT_CODE_CONFIG_IMPORT_REQUIRED, ], From 13574b461903ad8ac726e09ad3f6de015c670dbb Mon Sep 17 00:00:00 2001 From: alojua Date: Sat, 25 Nov 2017 17:33:14 +0100 Subject: [PATCH 3/3] Add 1 new line at the end of php files as it is needed to pass the static tests --- .../Magento/Deploy/Console/Command/App/ConfigStatusCommand.php | 2 +- .../Test/Unit/Console/Command/App/ConfigStatusCommandTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Deploy/Console/Command/App/ConfigStatusCommand.php b/app/code/Magento/Deploy/Console/Command/App/ConfigStatusCommand.php index 534a54918a396..90438380e2232 100644 --- a/app/code/Magento/Deploy/Console/Command/App/ConfigStatusCommand.php +++ b/app/code/Magento/Deploy/Console/Command/App/ConfigStatusCommand.php @@ -61,4 +61,4 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln('Config files are up to date.'); return Cli::RETURN_SUCCESS; } -} \ No newline at end of file +} diff --git a/app/code/Magento/Deploy/Test/Unit/Console/Command/App/ConfigStatusCommandTest.php b/app/code/Magento/Deploy/Test/Unit/Console/Command/App/ConfigStatusCommandTest.php index 3e400a28537e3..7822e75930eba 100644 --- a/app/code/Magento/Deploy/Test/Unit/Console/Command/App/ConfigStatusCommandTest.php +++ b/app/code/Magento/Deploy/Test/Unit/Console/Command/App/ConfigStatusCommandTest.php @@ -73,4 +73,4 @@ public function executeDataProvider() ], ]; } -} \ No newline at end of file +}