diff --git a/app/code/Magento/Swatches/Setup/UpgradeData.php b/app/code/Magento/Swatches/Setup/UpgradeData.php
index d9f72127c044..1d9b2856e172 100644
--- a/app/code/Magento/Swatches/Setup/UpgradeData.php
+++ b/app/code/Magento/Swatches/Setup/UpgradeData.php
@@ -43,7 +43,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
if (version_compare($context->getVersion(), '2.0.1', '<')) {
/** @var \Magento\Eav\Setup\EavSetup $eavSetup */
- $eavSetup = $this->eavSetupFactory->create();
+ $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$groupId = (int)$eavSetup->getAttributeGroupByCode(
Product::ENTITY,
'Default',
diff --git a/setup/src/Magento/Setup/Console/Command/AbstractModuleCommand.php b/setup/src/Magento/Setup/Console/Command/AbstractModuleCommand.php
index 41034aa34909..bd49bafe9459 100644
--- a/setup/src/Magento/Setup/Console/Command/AbstractModuleCommand.php
+++ b/setup/src/Magento/Setup/Console/Command/AbstractModuleCommand.php
@@ -84,14 +84,16 @@ protected function cleanup(InputInterface $input, OutputInterface $output)
/** @var \Magento\Framework\App\State\CleanupFiles $cleanupFiles */
$cleanupFiles = $this->objectManager->get('Magento\Framework\App\State\CleanupFiles');
$cleanupFiles->clearCodeGeneratedClasses();
- $output->writeln('Generated classes cleared successfully. Please re-run Magento compile command');
+ $output->writeln("Generated classes cleared successfully. Please run 'setup:di:compile' command to "
+ . 'generate classes.');
if ($input->getOption(self::INPUT_KEY_CLEAR_STATIC_CONTENT)) {
$cleanupFiles->clearMaterializedViewFiles();
$output->writeln('Generated static view files cleared successfully.');
} else {
$output->writeln(
- 'Info: Some modules might require static view files to be cleared. Use the optional --' .
- self::INPUT_KEY_CLEAR_STATIC_CONTENT . ' option to clear them.'
+ "Info: Some modules might require static view files to be cleared. To do this, run '"
+ . $this->getName() . "' with --" . self::INPUT_KEY_CLEAR_STATIC_CONTENT
+ . ' option to clear them.'
);
}
}
diff --git a/setup/src/Magento/Setup/Console/Command/AbstractModuleManageCommand.php b/setup/src/Magento/Setup/Console/Command/AbstractModuleManageCommand.php
index 143632420a22..bdf940920d34 100644
--- a/setup/src/Magento/Setup/Console/Command/AbstractModuleManageCommand.php
+++ b/setup/src/Magento/Setup/Console/Command/AbstractModuleManageCommand.php
@@ -6,8 +6,9 @@
namespace Magento\Setup\Console\Command;
use Symfony\Component\Console\Input\InputInterface;
-use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Input\InputOption;
+use Magento\Framework\App\DeploymentConfig;
abstract class AbstractModuleManageCommand extends AbstractModuleCommand
{
@@ -17,6 +18,11 @@ abstract class AbstractModuleManageCommand extends AbstractModuleCommand
const INPUT_KEY_ALL = 'all';
const INPUT_KEY_FORCE = 'force';
+ /**
+ * @var DeploymentConfig
+ */
+ protected $deploymentConfig;
+
/**
* {@inheritdoc}
*/
@@ -91,10 +97,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln('The following modules have been enabled:');
$output->writeln('- ' . implode("\n- ", $modulesToChange) . '');
$output->writeln('');
- $output->writeln(
- 'To make sure that the enabled modules are properly registered,'
- . " run 'setup:upgrade'."
- );
+ if ($this->getDeploymentConfig()->isAvailable()) {
+ $output->writeln(
+ 'To make sure that the enabled modules are properly registered,'
+ . " run 'setup:upgrade'."
+ );
+ }
} else {
$output->writeln('The following modules have been disabled:');
$output->writeln('- ' . implode("\n- ", $modulesToChange) . '');
@@ -134,4 +142,18 @@ protected function validate(array $modules)
* @return bool
*/
abstract protected function isEnable();
+
+ /**
+ * Get deployment config
+ *
+ * @return DeploymentConfig
+ * @deprecated
+ */
+ private function getDeploymentConfig()
+ {
+ if (!($this->deploymentConfig instanceof DeploymentConfig)) {
+ return $this->objectManager->get(DeploymentConfig::class);
+ }
+ return $this->deploymentConfig;
+ }
}
diff --git a/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php b/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php
index d86b29babc33..0b35d1be9d48 100644
--- a/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php
+++ b/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php
@@ -3,15 +3,17 @@
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-
namespace Magento\Setup\Console\Command;
+use Magento\Framework\ObjectManagerInterface;
+use Magento\Framework\Filesystem\DriverInterface;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
use Magento\Framework\Filesystem;
use Magento\Framework\App\Filesystem\DirectoryList;
-use Magento\Framework\Filesystem\DriverInterface;
-use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\Component\ComponentRegistrar;
+use Magento\Framework\Config\ConfigOptionsListConstants;
use Magento\Setup\Model\ObjectManagerProvider;
use Magento\Setup\Module\Di\App\Task\Manager;
use Magento\Setup\Module\Di\App\Task\OperationFactory;
@@ -19,8 +21,6 @@
use Magento\Setup\Module\Di\App\Task\OperationInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
-use Symfony\Component\Console\Input\InputInterface;
-use Symfony\Component\Console\Output\OutputInterface;
/**
* Command to run compile in single-tenant mode
@@ -107,8 +107,10 @@ protected function configure()
private function checkEnvironment()
{
$messages = [];
- if (!$this->deploymentConfig->isAvailable()) {
- $messages[] = 'You cannot run this command because the Magento application is not installed.';
+ $config = $this->deploymentConfig->get(ConfigOptionsListConstants::KEY_MODULES);
+ if (!$config) {
+ $messages[] = 'You cannot run this command because modules are not enabled. You can enable modules by'
+ . ' running \'module:enable --all\' command.';
}
return $messages;
diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php
index 51a65035ee92..8bd0713bea1d 100644
--- a/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php
+++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php
@@ -12,13 +12,13 @@
class DiCompileCommandTest extends \PHPUnit_Framework_TestCase
{
/** @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject */
- private $deploymentConfig;
+ private $deploymentConfigMock;
/** @var \Magento\Setup\Module\Di\App\Task\Manager|\PHPUnit_Framework_MockObject_MockObject */
- private $manager;
+ private $managerMock;
/** @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
- private $objectManager;
+ private $objectManagerMock;
/** @var DiCompileCommand|\PHPUnit_Framework_MockObject_MockObject */
private $command;
@@ -27,28 +27,28 @@ class DiCompileCommandTest extends \PHPUnit_Framework_TestCase
private $cacheMock;
/** @var \Magento\Framework\Filesystem|\PHPUnit_Framework_MockObject_MockObject */
- private $filesystem;
+ private $filesystemMock;
- /** @var \Magento\Framework\Filesystem\Driver\File | \PHPUnit_Framework_MockObject_MockObject*/
- private $fileDriver;
+ /** @var \Magento\Framework\Filesystem\Driver\File|\PHPUnit_Framework_MockObject_MockObject */
+ private $fileDriverMock;
- /** @var \Magento\Framework\App\Filesystem\DirectoryList | \PHPUnit_Framework_MockObject_MockObject*/
- private $directoryList;
+ /** @var \Magento\Framework\App\Filesystem\DirectoryList|\PHPUnit_Framework_MockObject_MockObject */
+ private $directoryListMock;
/** @var \Magento\Framework\Component\ComponentRegistrar|\PHPUnit_Framework_MockObject_MockObject */
- private $componentRegistrar;
+ private $componentRegistrarMock;
public function setUp()
{
- $this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false);
- $objectManagerProvider = $this->getMock(
+ $this->deploymentConfigMock = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false);
+ $objectManagerProviderMock = $this->getMock(
'Magento\Setup\Model\ObjectManagerProvider',
[],
[],
'',
false
);
- $this->objectManager = $this->getMockForAbstractClass(
+ $this->objectManagerMock = $this->getMockForAbstractClass(
'Magento\Framework\ObjectManagerInterface',
[],
'',
@@ -58,79 +58,86 @@ public function setUp()
->disableOriginalConstructor()
->getMock();
- $objectManagerProvider->expects($this->once())
+ $objectManagerProviderMock->expects($this->once())
->method('get')
- ->willReturn($this->objectManager);
- $this->manager = $this->getMock('Magento\Setup\Module\Di\App\Task\Manager', [], [], '', false);
- $this->directoryList = $this->getMock('Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false);
- $this->filesystem = $this->getMockBuilder('Magento\Framework\Filesystem')
+ ->willReturn($this->objectManagerMock);
+ $this->managerMock = $this->getMock('Magento\Setup\Module\Di\App\Task\Manager', [], [], '', false);
+ $this->directoryListMock = $this->getMock('Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false);
+ $this->filesystemMock = $this->getMockBuilder('Magento\Framework\Filesystem')
->disableOriginalConstructor()
->getMock();
- $this->fileDriver = $this->getMockBuilder('Magento\Framework\Filesystem\Driver\File')
+ $this->fileDriverMock = $this->getMockBuilder('Magento\Framework\Filesystem\Driver\File')
->disableOriginalConstructor()
->getMock();
- $this->componentRegistrar = $this->getMock(
+ $this->componentRegistrarMock = $this->getMock(
'\Magento\Framework\Component\ComponentRegistrar',
[],
[],
'',
false
);
- $this->componentRegistrar->expects($this->any())->method('getPaths')->willReturnMap([
+ $this->componentRegistrarMock->expects($this->any())->method('getPaths')->willReturnMap([
[ComponentRegistrar::MODULE, ['/path/to/module/one', '/path/to/module/two']],
[ComponentRegistrar::LIBRARY, ['/path/to/library/one', '/path/to/library/two']],
]);
$this->command = new DiCompileCommand(
- $this->deploymentConfig,
- $this->directoryList,
- $this->manager,
- $objectManagerProvider,
- $this->filesystem,
- $this->fileDriver,
- $this->componentRegistrar
+ $this->deploymentConfigMock,
+ $this->directoryListMock,
+ $this->managerMock,
+ $objectManagerProviderMock,
+ $this->filesystemMock,
+ $this->fileDriverMock,
+ $this->componentRegistrarMock
);
}
- public function testExecuteNotInstalled()
+ public function testExecuteModulesNotEnabled()
{
- $this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(false);
+ $this->deploymentConfigMock->expects($this->once())
+ ->method('get')
+ ->with(\Magento\Framework\Config\ConfigOptionsListConstants::KEY_MODULES)
+ ->willReturn(null);
$tester = new CommandTester($this->command);
$tester->execute([]);
$this->assertEquals(
- 'You cannot run this command because the Magento application is not installed.' . PHP_EOL,
+ 'You cannot run this command because modules are not enabled. You can enable modules by running \'module:'
+ . 'enable --all\' command.' . PHP_EOL,
$tester->getDisplay()
);
}
public function testExecute()
{
- $this->directoryList->expects($this->atLeastOnce())->method('getPath')->willReturn(null);
- $this->objectManager->expects($this->once())
+ $this->directoryListMock->expects($this->atLeastOnce())->method('getPath')->willReturn(null);
+ $this->objectManagerMock->expects($this->once())
->method('get')
->with('Magento\Framework\App\Cache')
->willReturn($this->cacheMock);
$this->cacheMock->expects($this->once())->method('clean');
$writeDirectory = $this->getMock('Magento\Framework\Filesystem\Directory\WriteInterface');
$writeDirectory->expects($this->atLeastOnce())->method('delete');
- $this->filesystem->expects($this->atLeastOnce())->method('getDirectoryWrite')->willReturn($writeDirectory);
+ $this->filesystemMock->expects($this->atLeastOnce())->method('getDirectoryWrite')->willReturn($writeDirectory);
- $this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(true);
+ $this->deploymentConfigMock->expects($this->once())
+ ->method('get')
+ ->with(\Magento\Framework\Config\ConfigOptionsListConstants::KEY_MODULES)
+ ->willReturn(['Magento_Catalog' => 1]);
$progressBar = $this->getMockBuilder(
'Symfony\Component\Console\Helper\ProgressBar'
)
->disableOriginalConstructor()
->getMock();
- $this->objectManager->expects($this->once())->method('configure');
- $this->objectManager
+ $this->objectManagerMock->expects($this->once())->method('configure');
+ $this->objectManagerMock
->expects($this->once())
->method('create')
->with('Symfony\Component\Console\Helper\ProgressBar')
->willReturn($progressBar);
- $this->manager->expects($this->exactly(7))->method('addOperation');
- $this->manager->expects($this->once())->method('process');
+ $this->managerMock->expects($this->exactly(7))->method('addOperation');
+ $this->managerMock->expects($this->once())->method('process');
$tester = new CommandTester($this->command);
$tester->execute([]);
$this->assertContains(
diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/ModuleEnableDisableCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/ModuleEnableDisableCommandTest.php
index 7001224977d1..551f3e7ebc2d 100644
--- a/setup/src/Magento/Setup/Test/Unit/Console/Command/ModuleEnableDisableCommandTest.php
+++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/ModuleEnableDisableCommandTest.php
@@ -14,46 +14,58 @@ class ModuleEnableDisableCommandTest extends \PHPUnit_Framework_TestCase
/**
* @var \Magento\Setup\Model\ObjectManagerProvider|\PHPUnit_Framework_MockObject_MockObject
*/
- private $objectManagerProvider;
+ private $objectManagerProviderMock;
/**
* @var \Magento\Framework\Module\Status|\PHPUnit_Framework_MockObject_MockObject
*/
- private $status;
+ private $statusMock;
/**
* @var \Magento\Framework\App\Cache|\PHPUnit_Framework_MockObject_MockObject
*/
- private $cache;
+ private $cacheMock;
/**
* @var \Magento\Framework\App\State\CleanupFiles|\PHPUnit_Framework_MockObject_MockObject
*/
- private $cleanupFiles;
+ private $cleanupFilesMock;
/**
* @var \Magento\Framework\Module\FullModuleList|\PHPUnit_Framework_MockObject_MockObject
*/
- private $fullModuleList;
+ private $fullModuleListMock;
+
+ /**
+ * @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject
+ */
+ private $deploymentConfigMock;
protected function setUp()
{
- $this->objectManagerProvider = $this->getMock('Magento\Setup\Model\ObjectManagerProvider', [], [], '', false);
+ $this->objectManagerProviderMock = $this->getMock(
+ 'Magento\Setup\Model\ObjectManagerProvider',
+ [],
+ [],
+ '',
+ false
+ );
$objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface');
- $this->objectManagerProvider->expects($this->any())
+ $this->objectManagerProviderMock->expects($this->any())
->method('get')
->will($this->returnValue($objectManager));
- $this->status = $this->getMock('Magento\Framework\Module\Status', [], [], '', false);
- $this->cache = $this->getMock('Magento\Framework\App\Cache', [], [], '', false);
- $this->cleanupFiles = $this->getMock('Magento\Framework\App\State\CleanupFiles', [], [], '', false);
- $this->fullModuleList = $this->getMock('Magento\Framework\Module\FullModuleList', [], [], '', false);
+ $this->statusMock = $this->getMock('Magento\Framework\Module\Status', [], [], '', false);
+ $this->cacheMock = $this->getMock('Magento\Framework\App\Cache', [], [], '', false);
+ $this->cleanupFilesMock = $this->getMock('Magento\Framework\App\State\CleanupFiles', [], [], '', false);
+ $this->fullModuleListMock = $this->getMock('Magento\Framework\Module\FullModuleList', [], [], '', false);
+ $this->deploymentConfigMock = $this->getMock(\Magento\Framework\App\DeploymentConfig::class, [], [], '', false);
$objectManager->expects($this->any())
->method('get')
->will($this->returnValueMap([
- ['Magento\Framework\Module\Status', $this->status],
- ['Magento\Framework\App\Cache', $this->cache],
- ['Magento\Framework\App\State\CleanupFiles', $this->cleanupFiles],
- ['Magento\Framework\Module\FullModuleList', $this->fullModuleList],
+ ['Magento\Framework\Module\Status', $this->statusMock],
+ ['Magento\Framework\App\Cache', $this->cacheMock],
+ ['Magento\Framework\App\State\CleanupFiles', $this->cleanupFilesMock],
+ ['Magento\Framework\Module\FullModuleList', $this->fullModuleListMock],
]));
}
@@ -66,35 +78,30 @@ protected function setUp()
*/
public function testExecute($isEnable, $clearStaticContent, $expectedMessage)
{
- $this->status->expects($this->once())
+ $this->statusMock->expects($this->once())
->method('getModulesToChange')
->with($isEnable, ['Magento_Module1', 'Magento_Module2'])
->will($this->returnValue(['Magento_Module1']));
-
- $this->status->expects($this->any())
+ $this->statusMock->expects($this->any())
->method('checkConstraints')
->will($this->returnValue([]));
-
- $this->status->expects($this->once())
+ $this->statusMock->expects($this->once())
->method('setIsEnabled')
->with($isEnable, ['Magento_Module1']);
-
- $this->cache->expects($this->once())
+ $this->cacheMock->expects($this->once())
->method('clean');
- $this->cleanupFiles->expects($this->once())
+ $this->cleanupFilesMock->expects($this->once())
->method('clearCodeGeneratedClasses');
- $this->cleanupFiles->expects($clearStaticContent ? $this->once() : $this->never())
+ $this->cleanupFilesMock->expects($clearStaticContent ? $this->once() : $this->never())
->method('clearMaterializedViewFiles');
-
- $commandTester = $isEnable
- ? new CommandTester(new ModuleEnableCommand($this->objectManagerProvider))
- : new CommandTester(new ModuleDisableCommand($this->objectManagerProvider));
+ $commandTester = $this->getCommandTester($isEnable);
$input = ['module' => ['Magento_Module1', 'Magento_Module2']];
if ($clearStaticContent) {
$input['--clear-static-content'] = true;
}
$commandTester->execute($input);
- $this->assertStringMatchesFormat($expectedMessage, $commandTester->getDisplay());
+ $display = $commandTester->getDisplay();
+ $this->assertStringMatchesFormat($expectedMessage, $display);
}
/**
@@ -106,14 +113,16 @@ public function executeDataProvider()
'enable, do not clear static content' => [
true,
false,
- '%amodules have been enabled%aMagento_Module1%a' .
- 'Info: Some modules might require static view files to be cleared.%a'
+ '%amodules have been enabled%aMagento_Module1%a'
+ . "Info: Some modules might require static view files to be cleared. To do this, run "
+ . "'module:enable' with --clear-static-content%a"
],
'disable, do not clear static content' => [
false,
false,
- '%amodules have been disabled%aMagento_Module1%a' .
- 'Info: Some modules might require static view files to be cleared.%a'
+ '%amodules have been disabled%aMagento_Module1%a'
+ . "Info: Some modules might require static view files to be cleared. To do this, run "
+ . "'module:disable' with --clear-static-content%a"
],
'enable, clear static content' => [
true,
@@ -124,17 +133,17 @@ public function executeDataProvider()
false,
true,
'%amodules have been disabled%aMagento_Module1%aGenerated static view files cleared%a'
- ],
+ ]
];
}
public function testExecuteEnableInvalidModule()
{
- $this->status->expects($this->once())
+ $this->statusMock->expects($this->once())
->method('getModulesToChange')
->with(true, ['invalid'])
->willThrowException(new \LogicException('Unknown module(s): invalid'));
- $commandTester = new CommandTester(new ModuleEnableCommand($this->objectManagerProvider));
+ $commandTester = $this->getCommandTester(true);
$input = ['module' => ['invalid']];
$commandTester->execute($input);
$this->assertEquals('Unknown module(s): invalid' . PHP_EOL, $commandTester->getDisplay());
@@ -142,11 +151,11 @@ public function testExecuteEnableInvalidModule()
public function testExecuteDisableInvalidModule()
{
- $this->status->expects($this->once())
+ $this->statusMock->expects($this->once())
->method('getModulesToChange')
->with(false, ['invalid'])
->willThrowException(new \LogicException('Unknown module(s): invalid'));
- $commandTester = new CommandTester(new ModuleDisableCommand($this->objectManagerProvider));
+ $commandTester = $this->getCommandTester(false);
$input = ['module' => ['invalid']];
$commandTester->execute($input);
$this->assertEquals('Unknown module(s): invalid' . PHP_EOL, $commandTester->getDisplay());
@@ -155,34 +164,44 @@ public function testExecuteDisableInvalidModule()
/**
* @param bool $isEnable
* @param string $expectedMessage
+ * @param bool $isInstalled
*
* @dataProvider executeAllDataProvider
*/
public function testExecuteAll($isEnable, $expectedMessage)
{
- $this->fullModuleList->expects($this->once())
+ $setupUpgradeMessage = 'To make sure that the enabled modules are properly registered, run \'setup:upgrade\'.';
+ $this->fullModuleListMock->expects($this->once())
->method('getNames')
->will($this->returnValue(['Magento_Module1', 'Magento_Module2']));
-
- $this->status->expects($this->once())
+ $this->statusMock->expects($this->once())
->method('getModulesToChange')
->with($isEnable, ['Magento_Module1', 'Magento_Module2'])
->will($this->returnValue(['Magento_Module1']));
-
- $this->status->expects($this->any())
+ $this->statusMock->expects($this->any())
->method('checkConstraints')
->will($this->returnValue([]));
-
- $this->status->expects($this->once())
+ $this->statusMock->expects($this->once())
->method('setIsEnabled')
->with($isEnable, ['Magento_Module1']);
-
- $commandTester = $isEnable
- ? new CommandTester(new ModuleEnableCommand($this->objectManagerProvider))
- : new CommandTester(new ModuleDisableCommand($this->objectManagerProvider));
+ if ($isEnable) {
+ $this->deploymentConfigMock->expects($this->once())
+ ->method('isAvailable')
+ ->willReturn(['Magento_Module1']);
+ } else {
+ $this->deploymentConfigMock->expects($this->never())
+ ->method('isAvailable');
+ }
+ $commandTester = $this->getCommandTester($isEnable);
$input = ['--all' => true];
$commandTester->execute($input);
- $this->assertStringMatchesFormat($expectedMessage, $commandTester->getDisplay());
+ $output = $commandTester->getDisplay();
+ $this->assertStringMatchesFormat($expectedMessage, $output);
+ if ($isEnable) {
+ $this->assertContains($setupUpgradeMessage, $output);
+ } else {
+ $this->assertNotContains($setupUpgradeMessage, $output);
+ }
}
/**
@@ -203,21 +222,16 @@ public function executeAllDataProvider()
*/
public function testExecuteWithConstraints($isEnable)
{
- $this->status->expects($this->once())
+ $this->statusMock->expects($this->once())
->method('getModulesToChange')
->with($isEnable, ['Magento_Module1', 'Magento_Module2'])
->will($this->returnValue(['Magento_Module1']));
-
- $this->status->expects($this->any())
+ $this->statusMock->expects($this->any())
->method('checkConstraints')
->will($this->returnValue(['constraint1', 'constraint2']));
-
- $this->status->expects($this->never())
+ $this->statusMock->expects($this->never())
->method('setIsEnabled');
-
- $commandTester = $isEnable
- ? new CommandTester(new ModuleEnableCommand($this->objectManagerProvider))
- : new CommandTester(new ModuleDisableCommand($this->objectManagerProvider));
+ $commandTester = $this->getCommandTester($isEnable);
$commandTester->execute(['module' => ['Magento_Module1', 'Magento_Module2']]);
$this->assertStringMatchesFormat(
'Unable to change status of modules%aconstraint1%aconstraint2%a',
@@ -244,21 +258,16 @@ public function executeWithConstraintsDataProvider()
*/
public function testExecuteForce($isEnable, $expectedMessage)
{
- $this->status->expects($this->once())
+ $this->statusMock->expects($this->once())
->method('getModulesToChange')
->with($isEnable, ['Magento_Module1', 'Magento_Module2'])
->will($this->returnValue(['Magento_Module1']));
-
- $this->status->expects($this->never())
+ $this->statusMock->expects($this->never())
->method('checkConstraints');
-
- $this->status->expects($this->once())
+ $this->statusMock->expects($this->once())
->method('setIsEnabled')
->with($isEnable, ['Magento_Module1']);
-
- $commandTester = $isEnable
- ? new CommandTester(new ModuleEnableCommand($this->objectManagerProvider))
- : new CommandTester(new ModuleDisableCommand($this->objectManagerProvider));
+ $commandTester = $this->getCommandTester($isEnable);
$commandTester->execute(['module' => ['Magento_Module1', 'Magento_Module2'], '--force' => true]);
$this->assertStringMatchesFormat(
$expectedMessage . '%amodules might not function properly%a',
@@ -284,21 +293,31 @@ public function executeExecuteForceDataProvider()
*/
public function testExecuteNoChanges($isEnable)
{
- $this->status->expects($this->once())
+ $this->statusMock->expects($this->once())
->method('getModulesToChange')
->with($isEnable, ['Magento_Module1', 'Magento_Module2'])
->will($this->returnValue([]));
-
- $this->status->expects($this->never())
+ $this->statusMock->expects($this->never())
->method('setIsEnabled');
-
- $commandTester = $isEnable
- ? new CommandTester(new ModuleEnableCommand($this->objectManagerProvider))
- : new CommandTester(new ModuleDisableCommand($this->objectManagerProvider));
+ $commandTester = $this->getCommandTester($isEnable);
$commandTester->execute(['module' => ['Magento_Module1', 'Magento_Module2']]);
$this->assertStringMatchesFormat(
'No modules were changed%a',
$commandTester->getDisplay()
);
}
+
+ /**
+ * @param bool $isEnable
+ * @return CommandTester
+ */
+ private function getCommandTester($isEnable)
+ {
+ $class = $isEnable ? ModuleEnableCommand::class : ModuleDisableCommand::class;
+ $command = new $class($this->objectManagerProviderMock);
+ $deploymentConfigProperty = new \ReflectionProperty($class, 'deploymentConfig');
+ $deploymentConfigProperty->setAccessible(true);
+ $deploymentConfigProperty->setValue($command, $this->deploymentConfigMock);
+ return new CommandTester($command);
+ }
}