From 5f4d25feca011a92329868e7b489d3d0923f044e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20Nu=C3=9F?= Date: Fri, 29 Sep 2017 11:20:56 +0200 Subject: [PATCH] Add developer-mode check to setup:upgrade command Add a check for application state/mode to setup:upgrade. If the mode is "developer" then don't show the di-recompile notice. If mode is something other than "developer", show the notice. --- .../Setup/Console/Command/UpgradeCommand.php | 27 ++++++++-- .../Console/Command/UpgradeCommandTest.php | 49 ++++++++++++++++--- 2 files changed, 66 insertions(+), 10 deletions(-) diff --git a/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php b/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php index a3d2ca3d8c408..475b083079cc7 100644 --- a/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php +++ b/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php @@ -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; @@ -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(); } @@ -90,7 +101,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $importConfigCommand->run($arrayInput, $output); } - if (!$keepGenerated) { + if (!$this->isDeveloperMode() && !$keepGenerated) { $output->writeln( 'Please re-run Magento compile command. Use the command "setup:di:compile"' ); @@ -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; + } } diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/UpgradeCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/UpgradeCommandTest.php index 59816ab77153b..900910b103ae1 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/UpgradeCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/UpgradeCommandTest.php @@ -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; @@ -29,6 +30,11 @@ class UpgradeCommandTest extends \PHPUnit\Framework\TestCase */ private $installerMock; + /** + * @var State|\PHPUnit_Framework_MockObject_MockObject + */ + private $stateMock; + /** * @var UpgradeCommand */ @@ -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'); @@ -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()); } @@ -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', ], ]; }