Skip to content

Commit

Permalink
Merge forwardport of #12441 to 2.3-develop branch
Browse files Browse the repository at this point in the history
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
magento-engcom-team authored Jan 24, 2018
2 parents cd5c72e + e1db353 commit b035660
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 0 deletions.
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;
}
}
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,
],
];
}
}
1 change: 1 addition & 0 deletions app/code/Magento/Deploy/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<item name="dumpApplicationCommand" xsi:type="object">\Magento\Deploy\Console\Command\App\ApplicationDumpCommand</item>
<item name="sensitiveConfigSetCommand" xsi:type="object">\Magento\Deploy\Console\Command\App\SensitiveConfigSetCommand</item>
<item name="configImportCommand" xsi:type="object">Magento\Deploy\Console\Command\App\ConfigImportCommand</item>
<item name="configStatusCommand" xsi:type="object">Magento\Deploy\Console\Command\App\ConfigStatusCommand</item>
</argument>
</arguments>
</type>
Expand Down

0 comments on commit b035660

Please sign in to comment.