-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge forwardport of #12441 to 2.3-develop branch
Applied pull request patch https://github.com/magento/magento2/pull/12441.patch (created by @jalogut) based on commit(s): 1. 8805bc0 2. e47ec9b 3. 13574b4
- Loading branch information
Showing
3 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
app/code/Magento/Deploy/Console/Command/App/ConfigStatusCommand.php
This file contains 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,64 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Deploy\Console\Command\App; | ||
|
||
use Magento\Deploy\Model\DeploymentConfig\ChangeDetector; | ||
use Magento\Framework\Console\Cli; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Command for checking if Config propagation is up to date | ||
*/ | ||
class ConfigStatusCommand extends Command | ||
{ | ||
/** | ||
* Code for error when config import is required. | ||
*/ | ||
const EXIT_CODE_CONFIG_IMPORT_REQUIRED = 2; | ||
|
||
/** | ||
* @var ChangeDetector | ||
*/ | ||
private $changeDetector; | ||
|
||
/** | ||
* ConfigStatusCommand constructor. | ||
* @param ChangeDetector $changeDetector | ||
*/ | ||
public function __construct(ChangeDetector $changeDetector) | ||
{ | ||
$this->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( | ||
'<info>Config files have changed. ' . | ||
'Run app:config:import or setup:upgrade command to synchronize configuration.</info>' | ||
); | ||
return self::EXIT_CODE_CONFIG_IMPORT_REQUIRED; | ||
} | ||
$output->writeln('<info>Config files are up to date.</info>'); | ||
return Cli::RETURN_SUCCESS; | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
app/code/Magento/Deploy/Test/Unit/Console/Command/App/ConfigStatusCommandTest.php
This file contains 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,76 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Deploy\Test\Unit\Console\Command\App; | ||
|
||
use Magento\Deploy\Console\Command\App\ConfigStatusCommand; | ||
use Magento\Deploy\Model\DeploymentConfig\ChangeDetector; | ||
use Magento\Framework\Console\Cli; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
class ConfigStatusCommandTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
|
||
/** | ||
* @var ConfigStatusCommand | ||
*/ | ||
private $command; | ||
/** | ||
* @var ChangeDetector | ||
*/ | ||
private $changeDetector; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->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, | ||
'Config files are up to date.' . PHP_EOL, | ||
Cli::RETURN_SUCCESS | ||
], | ||
'Config needs update' => [ | ||
true, | ||
'Config files have changed. ' . | ||
'Run app:config:import or setup:upgrade command to synchronize configuration.' . PHP_EOL, | ||
ConfigStatusCommand::EXIT_CODE_CONFIG_IMPORT_REQUIRED, | ||
], | ||
]; | ||
} | ||
} |
This file contains 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