Skip to content

Commit d3e0a7b

Browse files
authored
MAGETWO-81618: Only prompt for deploy command in production mode #11047
2 parents cb93fe5 + 0b2d85c commit d3e0a7b

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

setup/src/Magento/Setup/Console/Command/UpgradeCommand.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Setup\Console\Command;
77

88
use Magento\Deploy\Console\Command\App\ConfigImportCommand;
9+
use Magento\Framework\App\State as AppState;
910
use Magento\Framework\App\DeploymentConfig;
1011
use Magento\Framework\App\ObjectManager;
1112
use Magento\Framework\Setup\ConsoleLogger;
@@ -37,16 +38,25 @@ class UpgradeCommand extends AbstractSetupCommand
3738
*/
3839
private $deploymentConfig;
3940

41+
/**
42+
* @var AppState
43+
*/
44+
private $appState;
45+
4046
/**
4147
* Constructor
4248
*
4349
* @param InstallerFactory $installerFactory
4450
* @param DeploymentConfig $deploymentConfig
4551
*/
46-
public function __construct(InstallerFactory $installerFactory, DeploymentConfig $deploymentConfig = null)
47-
{
52+
public function __construct(
53+
InstallerFactory $installerFactory,
54+
DeploymentConfig $deploymentConfig = null,
55+
AppState $appState = null
56+
) {
4857
$this->installerFactory = $installerFactory;
4958
$this->deploymentConfig = $deploymentConfig ?: ObjectManager::getInstance()->get(DeploymentConfig::class);
59+
$this->appState = $appState ?: ObjectManager::getInstance()->get(AppState::class);
5060
parent::__construct();
5161
}
5262

@@ -90,7 +100,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
90100
$importConfigCommand->run($arrayInput, $output);
91101
}
92102

93-
if (!$keepGenerated) {
103+
if (!$keepGenerated && $this->appState->getMode() === AppState::MODE_PRODUCTION) {
94104
$output->writeln(
95105
'<info>Please re-run Magento compile command. Use the command "setup:di:compile"</info>'
96106
);

setup/src/Magento/Setup/Test/Unit/Console/Command/UpgradeCommandTest.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Setup\Test\Unit\Console\Command;
77

88
use Magento\Framework\App\DeploymentConfig;
9+
use Magento\Framework\App\State as AppState;
910
use Magento\Framework\Console\Cli;
1011
use Magento\Setup\Console\Command\UpgradeCommand;
1112
use Magento\Setup\Model\Installer;
@@ -29,11 +30,15 @@ class UpgradeCommandTest extends \PHPUnit\Framework\TestCase
2930
*/
3031
private $installerMock;
3132

33+
/**
34+
* @var AppState|\PHPUnit_Framework_MockObject_MockObject
35+
*/
36+
private $appStateMock;
37+
3238
/**
3339
* @var UpgradeCommand
3440
*/
3541
private $upgradeCommand;
36-
3742
/**
3843
* @var CommandTester
3944
*/
@@ -56,16 +61,24 @@ protected function setUp()
5661
$this->installerFactoryMock->expects($this->once())
5762
->method('create')
5863
->willReturn($this->installerMock);
64+
$this->appStateMock = $this->getMockBuilder(AppState::class)
65+
->disableOriginalConstructor()
66+
->getMock();
5967

60-
$this->upgradeCommand = new UpgradeCommand($this->installerFactoryMock, $this->deploymentConfigMock);
68+
$this->upgradeCommand = new UpgradeCommand(
69+
$this->installerFactoryMock,
70+
$this->deploymentConfigMock,
71+
$this->appStateMock
72+
);
6173
$this->commandTester = new CommandTester($this->upgradeCommand);
6274
}
6375

6476
/**
6577
* @dataProvider executeDataProvider
6678
*/
67-
public function testExecute($options, $expectedString = '')
79+
public function testExecute($options, $deployMode, $expectedString = '')
6880
{
81+
$this->appStateMock->method('getMode')->willReturn($deployMode);
6982
$this->installerMock->expects($this->at(0))
7083
->method('updateModulesSequence');
7184
$this->installerMock->expects($this->at(1))
@@ -85,11 +98,23 @@ public function executeDataProvider()
8598
return [
8699
[
87100
'options' => [],
101+
'deployMode' => \Magento\Framework\App\State::MODE_PRODUCTION,
88102
'expectedString' => 'Please re-run Magento compile command. Use the command "setup:di:compile"'
89103
. PHP_EOL
90104
],
91105
[
92106
'options' => ['--keep-generated' => true],
107+
'deployMode' => \Magento\Framework\App\State::MODE_PRODUCTION,
108+
'expectedString' => ''
109+
],
110+
[
111+
'options' => [],
112+
'deployMode' => \Magento\Framework\App\State::MODE_DEVELOPER,
113+
'expectedString' => ''
114+
],
115+
[
116+
'options' => [],
117+
'deployMode' => \Magento\Framework\App\State::MODE_DEFAULT,
93118
'expectedString' => ''
94119
],
95120
];

0 commit comments

Comments
 (0)