Skip to content

Commit bcaefa3

Browse files
author
Olga Kopylova
committed
Merge remote-tracking branch 'origin/MAGETWO-33519-clear-var-folder' into develop
2 parents ff6dcd2 + 75a4152 commit bcaefa3

File tree

10 files changed

+223
-18
lines changed

10 files changed

+223
-18
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\Module\ModuleList;
8+
9+
class DeploymentConfigFactoryTest extends \PHPUnit_Framework_TestCase
10+
{
11+
/**
12+
* @var DeploymentConfigFactory
13+
*/
14+
protected $object;
15+
16+
public function testCreate()
17+
{
18+
$this->object = new DeploymentConfigFactory();
19+
$this->assertInstanceOf(
20+
'Magento\Framework\Module\ModuleList\DeploymentConfig',
21+
$this->object->create(['Module_One' => 0, 'Module_Two' =>1])
22+
);
23+
}
24+
}

dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ class StatusTest extends \PHPUnit_Framework_TestCase
3838
*/
3939
private $dependencyChecker;
4040

41+
/**
42+
* @var \PHPUnit_Framework_MockObject_MockObject
43+
*/
44+
private $deploymentConfigFactory;
45+
4146
/**
4247
* @var Status
4348
*/
@@ -51,13 +56,21 @@ protected function setUp()
5156
$this->cleanup = $this->getMock('Magento\Framework\App\State\Cleanup', [], [], '', false);
5257
$this->conflictChecker = $this->getMock('Magento\Framework\Module\ConflictChecker', [], [], '', false);
5358
$this->dependencyChecker = $this->getMock('Magento\Framework\Module\DependencyChecker', [], [], '', false);
59+
$this->deploymentConfigFactory = $this->getMock(
60+
'Magento\Framework\Module\ModuleList\DeploymentConfigFactory',
61+
[],
62+
[],
63+
'',
64+
false
65+
);
5466
$this->object = new Status(
5567
$this->loader,
5668
$this->moduleList,
5769
$this->writer,
5870
$this->cleanup,
5971
$this->conflictChecker,
60-
$this->dependencyChecker
72+
$this->dependencyChecker,
73+
$this->deploymentConfigFactory
6174
);
6275
}
6376

@@ -165,10 +178,11 @@ public function testSetIsEnabled()
165178
$this->moduleList->expects($this->at(0))->method('has')->with('Module_Foo')->willReturn(false);
166179
$this->moduleList->expects($this->at(1))->method('has')->with('Module_Bar')->willReturn(false);
167180
$this->moduleList->expects($this->at(2))->method('has')->with('Module_Baz')->willReturn(false);
168-
$constraint = new \PHPUnit_Framework_Constraint_IsInstanceOf(
169-
'Magento\Framework\Module\ModuleList\DeploymentConfig'
170-
);
171-
$this->writer->expects($this->once())->method('update')->with($constraint);
181+
$deploymentConfig = $this->getMock('Magento\Framework\Module\ModuleList\DeploymentConfig', [], [], '', false);
182+
$expectedModules = ['Module_Foo' => 1, 'Module_Bar' => 1, 'Module_Baz' => 0];
183+
$this->deploymentConfigFactory->expects($this->once())->method('create')->with($expectedModules)
184+
->willReturn($deploymentConfig);
185+
$this->writer->expects($this->once())->method('update')->with($deploymentConfig);
172186
$this->cleanup->expects($this->once())->method('clearCaches');
173187
$this->cleanup->expects($this->once())->method('clearCodeGeneratedFiles');
174188
$this->object->setIsEnabled(true, ['Module_Foo', 'Module_Bar']);

dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,9 @@ public function testInstallDataAction()
163163

164164
public function testUpdateAction()
165165
{
166-
$this->installer->expects($this->once())->method('installSchema');
167-
$this->installer->expects($this->once())->method('installDataFixtures');
166+
$this->installer->expects($this->at(0))->method('updateModulesSequence');
167+
$this->installer->expects($this->at(1))->method('installSchema');
168+
$this->installer->expects($this->at(2))->method('installDataFixtures');
168169
$this->controller->updateAction();
169170
}
170171

dev/tests/unit/testsuite/Magento/Setup/Model/InstallerFactoryTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ public function testCreate()
1919
'Magento\Framework\App\DeploymentConfig\Writer',
2020
$this->getMock('Magento\Framework\App\DeploymentConfig\Writer', [], [], '', false),
2121
],
22+
[
23+
'Magento\Framework\App\DeploymentConfig\Reader',
24+
$this->getMock('Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false),
25+
],
2226
[
2327
'Magento\Framework\App\DeploymentConfig',
2428
$this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false),
@@ -27,6 +31,10 @@ public function testCreate()
2731
'Magento\Setup\Module\Setup',
2832
$this->getMock('Magento\Setup\Module\Setup', [], [], '', false),
2933
],
34+
[
35+
'Magento\Framework\Module\ModuleList\DeploymentConfigFactory',
36+
$this->getMock('Magento\Framework\Module\ModuleList\DeploymentConfigFactory', [], [], '', false),
37+
],
3038
[
3139
'Magento\Framework\Module\ModuleList',
3240
$this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false),

dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php

Lines changed: 77 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ class InstallerTest extends \PHPUnit_Framework_TestCase
3232
*/
3333
private $configWriter;
3434

35+
/**
36+
* @var \Magento\Framework\App\DeploymentConfig\Reader|\PHPUnit_Framework_MockObject_MockObject
37+
*/
38+
private $configReader;
39+
3540
/**
3641
* @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject
3742
*/
@@ -47,6 +52,16 @@ class InstallerTest extends \PHPUnit_Framework_TestCase
4752
*/
4853
private $moduleLoader;
4954

55+
/**
56+
* @var \Magento\Framework\Module\ModuleList\DeploymentConfigFactory|\PHPUnit_Framework_MockObject_MockObject
57+
*/
58+
private $deploymentConfigFactory;
59+
60+
/**
61+
* @var \Magento\Framework\Module\ModuleList\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject
62+
*/
63+
private $deploymentConfig;
64+
5065
/**
5166
* @var \Magento\Framework\App\Filesystem\DirectoryList|\PHPUnit_Framework_MockObject_MockObject
5267
*/
@@ -118,6 +133,7 @@ protected function setUp()
118133
{
119134
$this->filePermissions = $this->getMock('Magento\Setup\Model\FilePermissions', [], [], '', false);
120135
$this->configWriter = $this->getMock('Magento\Framework\App\DeploymentConfig\Writer', [], [], '', false);
136+
$this->configReader = $this->getMock('Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false);
121137
$this->config = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false);
122138

123139
$this->moduleList = $this->getMockForAbstractClass('Magento\Framework\Module\ModuleListInterface');
@@ -128,11 +144,20 @@ protected function setUp()
128144
['Foo_One', 'Bar_Two']
129145
);
130146
$this->moduleLoader = $this->getMock('Magento\Framework\Module\ModuleList\Loader', [], [], '', false);
131-
$allModules = [
132-
'Foo_One' => [],
133-
'Bar_Two' => [],
134-
];
135-
$this->moduleLoader->expects($this->any())->method('load')->willReturn($allModules);
147+
$this->deploymentConfigFactory = $this->getMock(
148+
'Magento\Framework\Module\ModuleList\DeploymentConfigFactory',
149+
[],
150+
[],
151+
'',
152+
false
153+
);
154+
$this->deploymentConfig = $this->getMock(
155+
'Magento\Framework\Module\ModuleList\DeploymentConfig',
156+
[],
157+
[],
158+
'',
159+
false
160+
);
136161
$this->directoryList = $this->getMock('Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false);
137162
$this->adminFactory = $this->getMock('Magento\Setup\Model\AdminAccountFactory', [], [], '', false);
138163
$this->logger = $this->getMockForAbstractClass('Magento\Setup\Model\LoggerInterface');
@@ -153,8 +178,7 @@ protected function setUp()
153178
* @param \PHPUnit_Framework_MockObject_MockObject|bool $objectManagerProvider
154179
* @return Installer
155180
*/
156-
private function createObject($connectionFactory = false, $objectManagerProvider = false)
157-
{
181+
private function createObject($connectionFactory = false, $objectManagerProvider = false) {
158182
if (!$connectionFactory) {
159183
$connectionFactory = $this->getMock('Magento\Setup\Module\ConnectionFactory', [], [], '', false);
160184
$connectionFactory->expects($this->any())->method('create')->willReturn($this->connection);
@@ -163,10 +187,13 @@ private function createObject($connectionFactory = false, $objectManagerProvider
163187
$objectManagerProvider = $this->getMock('Magento\Setup\Model\ObjectManagerProvider', [], [], '', false);
164188
$objectManagerProvider->expects($this->any())->method('get')->willReturn($this->objectManager);
165189
}
190+
166191
return new Installer(
167192
$this->filePermissions,
168193
$this->configWriter,
194+
$this->configReader,
169195
$this->config,
196+
$this->deploymentConfigFactory,
170197
$this->moduleList,
171198
$this->moduleLoader,
172199
$this->directoryList,
@@ -196,7 +223,12 @@ public function testInstall()
196223
[DbConfig::CONFIG_KEY, self::$dbConfig],
197224
[EncryptConfig::CONFIG_KEY, [EncryptConfig::KEY_ENCRYPTION_KEY => 'encryption_key']]
198225
]));
199-
226+
$allModules = ['Foo_One' => [], 'Bar_Two' => []];
227+
$this->moduleLoader->expects($this->any())->method('load')->willReturn($allModules);
228+
$modules = ['Foo_One' => 1, 'Bar_Two' => 1 ];
229+
$this->deploymentConfig->expects($this->any())->method('getData')->willReturn($modules);
230+
$this->deploymentConfigFactory->expects($this->any())->method('create')->with($modules)
231+
->willReturn($this->deploymentConfig);
200232
$setup = $this->getMock('Magento\Setup\Module\Setup', [], [], '', false);
201233
$table = $this->getMock('Magento\Framework\DB\Ddl\Table', [], [], '', false);
202234
$connection = $this->getMockForAbstractClass('Magento\Framework\DB\Adapter\AdapterInterface');
@@ -282,6 +314,43 @@ public function testCheckApplicationFilePermissions()
282314
$this->assertSame(['message' => [$expectedMessage]], $this->object->getInstallInfo());
283315
}
284316

317+
public function testUpdateModulesSequence()
318+
{
319+
$varDir = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\WriteInterface');
320+
$varDir->expects($this->exactly(2))->method('getAbsolutePath')->willReturn('/var');
321+
$this->filesystem
322+
->expects($this->exactly(2))
323+
->method('getDirectoryWrite')
324+
->willReturn($varDir);
325+
326+
$allModules = [
327+
'Foo_One' => [],
328+
'Bar_Two' => [],
329+
'New_Module' => [],
330+
];
331+
$this->moduleLoader->expects($this->once())->method('load')->willReturn($allModules);
332+
333+
$expectedModules = [
334+
'Bar_Two' => 0,
335+
'Foo_One' => 1,
336+
'New_Module' => 1
337+
];
338+
339+
$this->config->expects($this->atLeastOnce())->method('isAvailable')->willReturn(true);
340+
$this->deploymentConfigFactory->expects($this->once())->method('create')->with($expectedModules)
341+
->willReturn($this->deploymentConfig);
342+
343+
$newObject = $this->createObject(false, false);
344+
$this->configReader->expects($this->once())->method('load')
345+
->willReturn(['modules' => ['Bar_Two' => 0, 'Foo_One' => 1, 'Old_Module' => 0] ]);
346+
$this->configWriter->expects($this->once())->method('update')->with($this->deploymentConfig);
347+
$this->logger->expects($this->at(0))->method('log')->with('File system cleanup:');
348+
$this->logger->expects($this->at(1))->method('log')
349+
->with('The directory \'/var\' doesn\'t exist - skipping cleanup');
350+
$this->logger->expects($this->at(3))->method('log')->with('Updating modules:');
351+
$newObject->updateModulesSequence();
352+
}
353+
285354
public function testUninstall()
286355
{
287356
$this->config->expects($this->once())->method('isAvailable')->willReturn(false);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\Module\ModuleList;
8+
9+
/**
10+
* Factory for Deployment configuration segment for modules
11+
*/
12+
class DeploymentConfigFactory
13+
{
14+
/**
15+
* Factory method for Deployment Config object
16+
*
17+
* @param array $data
18+
* @return DeploymentConfig
19+
*/
20+
public function create(array $data)
21+
{
22+
return new DeploymentConfig($data);
23+
}
24+
}

lib/internal/Magento/Framework/Module/Status.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
namespace Magento\Framework\Module;
88

99
use Magento\Framework\App\DeploymentConfig\Writer;
10+
use Magento\Framework\Module\ModuleList\DeploymentConfigFactory;
1011
use Magento\Framework\App\State\Cleanup;
1112

1213
/**
1314
* A service for controlling module status
15+
*
16+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1417
*/
1518
class Status
1619
{
@@ -56,6 +59,13 @@ class Status
5659
*/
5760
private $conflictChecker;
5861

62+
/**
63+
* Factory to create module deployment config object
64+
*
65+
* @var DeploymentConfigFactory
66+
*/
67+
private $deploymentConfigFactory;
68+
5969
/**
6070
* Constructor
6171
*
@@ -65,21 +75,24 @@ class Status
6575
* @param Cleanup $cleanup
6676
* @param ConflictChecker $conflictChecker
6777
* @param DependencyChecker $dependencyChecker
78+
* @param DeploymentConfigFactory $deploymentConfigFactory
6879
*/
6980
public function __construct(
7081
ModuleList\Loader $loader,
7182
ModuleList $list,
7283
Writer $writer,
7384
Cleanup $cleanup,
7485
ConflictChecker $conflictChecker,
75-
DependencyChecker $dependencyChecker
86+
DependencyChecker $dependencyChecker,
87+
DeploymentConfigFactory $deploymentConfigFactory
7688
) {
7789
$this->loader = $loader;
7890
$this->list = $list;
7991
$this->writer = $writer;
8092
$this->cleanup = $cleanup;
8193
$this->conflictChecker = $conflictChecker;
8294
$this->dependencyChecker = $dependencyChecker;
95+
$this->deploymentConfigFactory = $deploymentConfigFactory;
8396
}
8497

8598
/**
@@ -159,7 +172,7 @@ public function setIsEnabled($isEnabled, $modules)
159172
$result[$name] = $currentStatus;
160173
}
161174
}
162-
$segment = new ModuleList\DeploymentConfig($result);
175+
$segment = $this->deploymentConfigFactory->create($result);
163176
$this->writer->update($segment);
164177
$this->cleanup->clearCaches();
165178
$this->cleanup->clearCodeGeneratedFiles();

setup/src/Magento/Setup/Controller/ConsoleController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ public function installDataAction()
407407
*/
408408
public function updateAction()
409409
{
410+
$this->installer->updateModulesSequence();
410411
$this->installer->installSchema();
411412
$this->installer->installDataFixtures();
412413
}

0 commit comments

Comments
 (0)