Skip to content

Commit

Permalink
Merge branch 'MAGETWO-51592-make-single-tenant-compiler-work' into or…
Browse files Browse the repository at this point in the history
…igin-develop
  • Loading branch information
Igor Melnikov committed Apr 21, 2016
2 parents ebba9e7 + 04db3e4 commit beecd22
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 129 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Swatches/Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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('<info>Generated classes cleared successfully. Please re-run Magento compile command</info>');
$output->writeln("<info>Generated classes cleared successfully. Please run 'setup:di:compile' command to "
. 'generate classes.</info>');
if ($input->getOption(self::INPUT_KEY_CLEAR_STATIC_CONTENT)) {
$cleanupFiles->clearMaterializedViewFiles();
$output->writeln('<info>Generated static view files cleared successfully.</info>');
} else {
$output->writeln(
'<info>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>'
"<info>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.</info>'
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -17,6 +18,11 @@ abstract class AbstractModuleManageCommand extends AbstractModuleCommand
const INPUT_KEY_ALL = 'all';
const INPUT_KEY_FORCE = 'force';

/**
* @var DeploymentConfig
*/
protected $deploymentConfig;

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -91,10 +97,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln('<info>The following modules have been enabled:</info>');
$output->writeln('<info>- ' . implode("\n- ", $modulesToChange) . '</info>');
$output->writeln('');
$output->writeln(
'<info>To make sure that the enabled modules are properly registered,'
. " run 'setup:upgrade'.</info>"
);
if ($this->getDeploymentConfig()->isAvailable()) {
$output->writeln(
'<info>To make sure that the enabled modules are properly registered,'
. " run 'setup:upgrade'.</info>"
);
}
} else {
$output->writeln('<info>The following modules have been disabled:</info>');
$output->writeln('<info>- ' . implode("\n- ", $modulesToChange) . '</info>');
Expand Down Expand Up @@ -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;
}
}
16 changes: 9 additions & 7 deletions setup/src/Magento/Setup/Console/Command/DiCompileCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
* 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;
use Magento\Setup\Module\Di\App\Task\OperationException;
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
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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',
[],
'',
Expand All @@ -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(
Expand Down
Loading

0 comments on commit beecd22

Please sign in to comment.