Skip to content

Commit defca19

Browse files
committed
MAGETWO-33555: [GITHUB] After update, config.php is not updated with correct sequence #1015
- fix for updating modules with new sequence.
1 parent 8ccdc20 commit defca19

File tree

10 files changed

+215
-22
lines changed

10 files changed

+215
-22
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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 Magento\Framework\Module\ModuleList\DeploymentConfigFactory
13+
*/
14+
protected $object;
15+
16+
public function testCreate()
17+
{
18+
$helper = new \Magento\TestFramework\Helper\ObjectManager($this);
19+
$this->object = $helper->getObject('Magento\Framework\Module\ModuleList\DeploymentConfigFactory');
20+
$this->object->create(['Module_One' => 0, 'Module_Two' =>1]);
21+
}
22+
}

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ public function testUpdateAction()
165165
{
166166
$this->installer->expects($this->once())->method('installSchema');
167167
$this->installer->expects($this->once())->method('installDataFixtures');
168+
$this->installer->expects($this->once())->method('updateModulesInDeploymentConfig');
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: 81 additions & 14 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
*/
@@ -42,11 +47,6 @@ class InstallerTest extends \PHPUnit_Framework_TestCase
4247
*/
4348
private $moduleList;
4449

45-
/**
46-
* @var \Magento\Framework\Module\ModuleList\Loader|\PHPUnit_Framework_MockObject_MockObject
47-
*/
48-
private $moduleLoader;
49-
5050
/**
5151
* @var \Magento\Framework\App\Filesystem\DirectoryList|\PHPUnit_Framework_MockObject_MockObject
5252
*/
@@ -118,6 +118,7 @@ protected function setUp()
118118
{
119119
$this->filePermissions = $this->getMock('Magento\Setup\Model\FilePermissions', [], [], '', false);
120120
$this->configWriter = $this->getMock('Magento\Framework\App\DeploymentConfig\Writer', [], [], '', false);
121+
$this->configReader = $this->getMock('Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false);
121122
$this->config = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false);
122123

123124
$this->moduleList = $this->getMockForAbstractClass('Magento\Framework\Module\ModuleListInterface');
@@ -127,12 +128,6 @@ protected function setUp()
127128
$this->moduleList->expects($this->any())->method('getNames')->willReturn(
128129
['Foo_One', 'Bar_Two']
129130
);
130-
$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);
136131
$this->directoryList = $this->getMock('Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false);
137132
$this->adminFactory = $this->getMock('Magento\Setup\Model\AdminAccountFactory', [], [], '', false);
138133
$this->logger = $this->getMockForAbstractClass('Magento\Setup\Model\LoggerInterface');
@@ -151,10 +146,16 @@ protected function setUp()
151146
*
152147
* @param \PHPUnit_Framework_MockObject_MockObject|bool $connectionFactory
153148
* @param \PHPUnit_Framework_MockObject_MockObject|bool $objectManagerProvider
149+
* @param \PHPUnit_Framework_MockObject_MockObject|bool $moduleLoader
150+
* @param \PHPUnit_Framework_MockObject_MockObject|bool $deploymentConfigFactory
154151
* @return Installer
155152
*/
156-
private function createObject($connectionFactory = false, $objectManagerProvider = false)
157-
{
153+
private function createObject(
154+
$connectionFactory = false,
155+
$objectManagerProvider = false,
156+
$moduleLoader = false,
157+
$deploymentConfigFactory = false
158+
) {
158159
if (!$connectionFactory) {
159160
$connectionFactory = $this->getMock('Magento\Setup\Module\ConnectionFactory', [], [], '', false);
160161
$connectionFactory->expects($this->any())->method('create')->willReturn($this->connection);
@@ -163,12 +164,42 @@ private function createObject($connectionFactory = false, $objectManagerProvider
163164
$objectManagerProvider = $this->getMock('Magento\Setup\Model\ObjectManagerProvider', [], [], '', false);
164165
$objectManagerProvider->expects($this->any())->method('get')->willReturn($this->objectManager);
165166
}
167+
if (!$moduleLoader) {
168+
$moduleLoader = $this->getMock('Magento\Framework\Module\ModuleList\Loader', [], [], '', false);
169+
$allModules = [
170+
'Foo_One' => [],
171+
'Bar_Two' => [],
172+
];
173+
$moduleLoader->expects($this->any())->method('load')->willReturn($allModules);
174+
}
175+
if (!$deploymentConfigFactory) {
176+
$deploymentConfigFactory = $this->getMock(
177+
'Magento\Framework\Module\ModuleList\DeploymentConfigFactory',
178+
[],
179+
[],
180+
'',
181+
false
182+
);
183+
$modules = ['Foo_One' => 1, 'Bar_Two' => 1 ];
184+
$deploymentConfig = $this->getMock(
185+
'Magento\Framework\Module\ModuleList\DeploymentConfig',
186+
[],
187+
[],
188+
'',
189+
false
190+
);
191+
$deploymentConfig->expects($this->any())->method('getData')->willReturn($modules);
192+
$deploymentConfigFactory->expects($this->any())->method('create')->with($modules)
193+
->willReturn($deploymentConfig);
194+
}
166195
return new Installer(
167196
$this->filePermissions,
168197
$this->configWriter,
198+
$this->configReader,
169199
$this->config,
200+
$deploymentConfigFactory,
170201
$this->moduleList,
171-
$this->moduleLoader,
202+
$moduleLoader,
172203
$this->directoryList,
173204
$this->adminFactory,
174205
$this->logger,
@@ -280,6 +311,42 @@ public function testCheckApplicationFilePermissions()
280311
$this->assertSame(['message' => [$expectedMessage]], $this->object->getInstallInfo());
281312
}
282313

314+
public function testUpdateModulesInDeploymentConfig()
315+
{
316+
$moduleLoader = $this->getMock('Magento\Framework\Module\ModuleList\Loader', [], [], '', false);
317+
$allModules = [
318+
'Foo_One' => [],
319+
'Bar_Two' => [],
320+
'New_Module' => [],
321+
];
322+
$moduleLoader->expects($this->once())->method('load')->willReturn($allModules);
323+
324+
$deploymentConfigFactory = $this->getMock(
325+
'Magento\Framework\Module\ModuleList\DeploymentConfigFactory',
326+
[],
327+
[],
328+
'',
329+
false
330+
);
331+
$expectedModules = [
332+
'Bar_Two' => 0,
333+
'Foo_One' => 1,
334+
'New_Module' => 1
335+
];
336+
$deploymentConfig = $this->getMock('Magento\Framework\Module\ModuleList\DeploymentConfig', [], [], '', false);
337+
338+
$deploymentConfigFactory->expects($this->any())->method('create')->with($expectedModules)
339+
->willReturn($deploymentConfig);
340+
341+
$newObject = $this->createObject(false, false, $moduleLoader, $deploymentConfigFactory);
342+
$this->configReader->expects($this->once())->method('load')
343+
->willReturn(['modules' => ['Bar_Two' => 0, 'Foo_One' => 1, 'Old_Module' => 0] ]);
344+
$deploymentConfigFactory->expects($this->once())->method('create')->with($expectedModules)
345+
->willReturn($deploymentConfig);
346+
$this->configWriter->expects($this->once())->method('update')->with($deploymentConfig);
347+
$newObject->updateModulesInDeploymentConfig();
348+
}
349+
283350
public function testUninstall()
284351
{
285352
$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+
* 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: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
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
/**
@@ -56,6 +57,13 @@ class Status
5657
*/
5758
private $conflictChecker;
5859

60+
/**
61+
* factory to create module deployment config object
62+
*
63+
* @var DeploymentConfigFactory
64+
*/
65+
private $deploymentConfigFactory;
66+
5967
/**
6068
* Constructor
6169
*
@@ -65,21 +73,24 @@ class Status
6573
* @param Cleanup $cleanup
6674
* @param ConflictChecker $conflictChecker
6775
* @param DependencyChecker $dependencyChecker
76+
* @param DeploymentConfigFactory $deploymentConfigFactory
6877
*/
6978
public function __construct(
7079
ModuleList\Loader $loader,
7180
ModuleList $list,
7281
Writer $writer,
7382
Cleanup $cleanup,
7483
ConflictChecker $conflictChecker,
75-
DependencyChecker $dependencyChecker
84+
DependencyChecker $dependencyChecker,
85+
DeploymentConfigFactory $deploymentConfigFactory
7686
) {
7787
$this->loader = $loader;
7888
$this->list = $list;
7989
$this->writer = $writer;
8090
$this->cleanup = $cleanup;
8191
$this->conflictChecker = $conflictChecker;
8292
$this->dependencyChecker = $dependencyChecker;
93+
$this->deploymentConfigFactory = $deploymentConfigFactory;
8394
}
8495

8596
/**
@@ -159,7 +170,7 @@ public function setIsEnabled($isEnabled, $modules)
159170
$result[$name] = $currentStatus;
160171
}
161172
}
162-
$segment = new ModuleList\DeploymentConfig($result);
173+
$segment = $this->deploymentConfigFactory->create($result);
163174
$this->writer->update($segment);
164175
$this->cleanup->clearCaches();
165176
$this->cleanup->clearCodeGeneratedFiles();

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ public function installDataAction()
405405
*/
406406
public function updateAction()
407407
{
408+
$this->installer->updateModulesInDeploymentConfig();
408409
$this->installer->installSchema();
409410
$this->installer->installDataFixtures();
410411
}

0 commit comments

Comments
 (0)