Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit b035660

Browse files
Merge forwardport of magento/magento2#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
2 parents cd5c72e + e1db353 commit b035660

File tree

3 files changed

+141
-0
lines changed

3 files changed

+141
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Deploy\Console\Command\App;
7+
8+
use Magento\Deploy\Model\DeploymentConfig\ChangeDetector;
9+
use Magento\Framework\Console\Cli;
10+
use Symfony\Component\Console\Command\Command;
11+
use Symfony\Component\Console\Input\InputInterface;
12+
use Symfony\Component\Console\Output\OutputInterface;
13+
14+
/**
15+
* Command for checking if Config propagation is up to date
16+
*/
17+
class ConfigStatusCommand extends Command
18+
{
19+
/**
20+
* Code for error when config import is required.
21+
*/
22+
const EXIT_CODE_CONFIG_IMPORT_REQUIRED = 2;
23+
24+
/**
25+
* @var ChangeDetector
26+
*/
27+
private $changeDetector;
28+
29+
/**
30+
* ConfigStatusCommand constructor.
31+
* @param ChangeDetector $changeDetector
32+
*/
33+
public function __construct(ChangeDetector $changeDetector)
34+
{
35+
$this->changeDetector = $changeDetector;
36+
parent::__construct();
37+
}
38+
39+
/**
40+
* {@inheritdoc}
41+
*/
42+
protected function configure()
43+
{
44+
$this->setName('app:config:status')
45+
->setDescription('Checks if config propagation requires update');
46+
parent::configure();
47+
}
48+
49+
/**
50+
* {@inheritdoc}
51+
*/
52+
protected function execute(InputInterface $input, OutputInterface $output)
53+
{
54+
if ($this->changeDetector->hasChanges()) {
55+
$output->writeln(
56+
'<info>Config files have changed. ' .
57+
'Run app:config:import or setup:upgrade command to synchronize configuration.</info>'
58+
);
59+
return self::EXIT_CODE_CONFIG_IMPORT_REQUIRED;
60+
}
61+
$output->writeln('<info>Config files are up to date.</info>');
62+
return Cli::RETURN_SUCCESS;
63+
}
64+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Deploy\Test\Unit\Console\Command\App;
7+
8+
use Magento\Deploy\Console\Command\App\ConfigStatusCommand;
9+
use Magento\Deploy\Model\DeploymentConfig\ChangeDetector;
10+
use Magento\Framework\Console\Cli;
11+
use Symfony\Component\Console\Tester\CommandTester;
12+
13+
/**
14+
* @inheritdoc
15+
*/
16+
class ConfigStatusCommandTest extends \PHPUnit\Framework\TestCase
17+
{
18+
19+
/**
20+
* @var ConfigStatusCommand
21+
*/
22+
private $command;
23+
/**
24+
* @var ChangeDetector
25+
*/
26+
private $changeDetector;
27+
28+
/**
29+
* @inheritdoc
30+
*/
31+
protected function setUp()
32+
{
33+
$this->changeDetector = $this->getMockBuilder(ChangeDetector::class)
34+
->disableOriginalConstructor()
35+
->getMock();
36+
37+
$this->command = new ConfigStatusCommand($this->changeDetector);
38+
}
39+
40+
/**
41+
* @param bool $hasChanges
42+
* @param string $expectedMessage
43+
* @param int $expectedCode
44+
*
45+
* @dataProvider executeDataProvider
46+
*/
47+
public function testExecute(bool $hasChanges, $expectedMessage, $expectedCode)
48+
{
49+
$this->changeDetector->expects($this->once())
50+
->method('hasChanges')
51+
->will($this->returnValue($hasChanges));
52+
53+
$tester = new CommandTester($this->command);
54+
$tester->execute([]);
55+
56+
$this->assertEquals($expectedMessage, $tester->getDisplay());
57+
$this->assertSame($expectedCode, $tester->getStatusCode());
58+
}
59+
60+
public function executeDataProvider()
61+
{
62+
return [
63+
'Config is up to date' => [
64+
false,
65+
'Config files are up to date.' . PHP_EOL,
66+
Cli::RETURN_SUCCESS
67+
],
68+
'Config needs update' => [
69+
true,
70+
'Config files have changed. ' .
71+
'Run app:config:import or setup:upgrade command to synchronize configuration.' . PHP_EOL,
72+
ConfigStatusCommand::EXIT_CODE_CONFIG_IMPORT_REQUIRED,
73+
],
74+
];
75+
}
76+
}

app/code/Magento/Deploy/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<item name="dumpApplicationCommand" xsi:type="object">\Magento\Deploy\Console\Command\App\ApplicationDumpCommand</item>
3232
<item name="sensitiveConfigSetCommand" xsi:type="object">\Magento\Deploy\Console\Command\App\SensitiveConfigSetCommand</item>
3333
<item name="configImportCommand" xsi:type="object">Magento\Deploy\Console\Command\App\ConfigImportCommand</item>
34+
<item name="configStatusCommand" xsi:type="object">Magento\Deploy\Console\Command\App\ConfigStatusCommand</item>
3435
</argument>
3536
</arguments>
3637
</type>

0 commit comments

Comments
 (0)