Skip to content

Add command "app:config:status" to check if "app:config:import" needed #12441

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
merged 3 commits into from
Dec 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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