Skip to content
Closed
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
27 changes: 24 additions & 3 deletions setup/src/Magento/Setup/Console/Command/UpgradeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Magento\Deploy\Console\Command\App\ConfigImportCommand;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\App\State;
use Magento\Framework\Setup\ConsoleLogger;
use Magento\Setup\Model\InstallerFactory;
use Symfony\Component\Console\Input\ArrayInput;
Expand Down Expand Up @@ -37,16 +38,26 @@ class UpgradeCommand extends AbstractSetupCommand
*/
private $deploymentConfig;

/**
* @var State
*/
private $state;

/**
* Constructor
*
* @param InstallerFactory $installerFactory
* @param DeploymentConfig $deploymentConfig
* @param State $state
*/
public function __construct(InstallerFactory $installerFactory, DeploymentConfig $deploymentConfig = null)
{
public function __construct(
InstallerFactory $installerFactory,
DeploymentConfig $deploymentConfig = null,
State $state = null
) {
$this->installerFactory = $installerFactory;
$this->deploymentConfig = $deploymentConfig ?: ObjectManager::getInstance()->get(DeploymentConfig::class);
$this->state = $state ?? ObjectManager::getInstance()->get(State::class);
parent::__construct();
}

Expand Down Expand Up @@ -90,7 +101,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$importConfigCommand->run($arrayInput, $output);
}

if (!$keepGenerated) {
if (!$this->isDeveloperMode() && !$keepGenerated) {
$output->writeln(
'<info>Please re-run Magento compile command. Use the command "setup:di:compile"</info>'
);
Expand All @@ -102,4 +113,14 @@ protected function execute(InputInterface $input, OutputInterface $output)

return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
}

/**
* Return whether the application is in developer mode.
*
* @return bool
*/
private function isDeveloperMode()
{
return $this->state->getMode() === State::MODE_DEVELOPER;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\Setup\Test\Unit\Console\Command;

use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\App\State;
use Magento\Framework\Console\Cli;
use Magento\Setup\Console\Command\UpgradeCommand;
use Magento\Setup\Model\Installer;
Expand All @@ -29,6 +30,11 @@ class UpgradeCommandTest extends \PHPUnit\Framework\TestCase
*/
private $installerMock;

/**
* @var State|\PHPUnit_Framework_MockObject_MockObject
*/
private $stateMock;

/**
* @var UpgradeCommand
*/
Expand Down Expand Up @@ -56,15 +62,23 @@ protected function setUp()
$this->installerFactoryMock->expects($this->once())
->method('create')
->willReturn($this->installerMock);
$this->stateMock = $this->getMockBuilder(State::class)
->disableOriginalConstructor()
->getMock();

$this->upgradeCommand = new UpgradeCommand(
$this->installerFactoryMock,
$this->deploymentConfigMock,
$this->stateMock
);

$this->upgradeCommand = new UpgradeCommand($this->installerFactoryMock, $this->deploymentConfigMock);
$this->commandTester = new CommandTester($this->upgradeCommand);
}

/**
* @dataProvider executeDataProvider
*/
public function testExecute($options, $expectedString = '')
public function testExecute($options, $expectedString = '', $state = 'developer')
{
$this->installerMock->expects($this->at(0))
->method('updateModulesSequence');
Expand All @@ -73,6 +87,10 @@ public function testExecute($options, $expectedString = '')
$this->installerMock->expects($this->at(2))
->method('installDataFixtures');

$this->stateMock->expects($this->once())
->method('getMode')
->willReturn($state);

$this->assertSame(Cli::RETURN_SUCCESS, $this->commandTester->execute($options));
$this->assertEquals($expectedString, $this->commandTester->getDisplay());
}
Expand All @@ -82,15 +100,32 @@ public function testExecute($options, $expectedString = '')
*/
public function executeDataProvider()
{
$rerunDiCompileString = 'Please re-run Magento compile command. Use the command "setup:di:compile"' . PHP_EOL;

return [
// "developer" & don't keep generated
[
'options' => [],
'expectedString' => '',
'state' => State::MODE_DEVELOPER,
],
// "developer" & keep generated
[
'options' => ['--keep-generated' => true],
'expectedString' => '',
'state' => State::MODE_DEVELOPER,
],
// not "developer" & don't keep generated
[
'options' => [],
'expectedString' => 'Please re-run Magento compile command. Use the command "setup:di:compile"'
. PHP_EOL
'options' => [],
'expectedString' => $rerunDiCompileString,
'state' => 'not_developer',
],
// not "developer" & keep generated
[
'options' => ['--keep-generated' => true],
'expectedString' => ''
'options' => ['--keep-generated' => true],
'expectedString' => '',
'state' => 'not_developer',
],
];
}
Expand Down