Skip to content

Commit 94a8c24

Browse files
Igor Melnikovvrann
authored andcommitted
MAGETWO-51592: Make single tenant compiler work when Magento not installed
Updating unit test
1 parent 401aba3 commit 94a8c24

File tree

2 files changed

+69
-74
lines changed

2 files changed

+69
-74
lines changed

setup/src/Magento/Setup/Console/Command/AbstractModuleManageCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ abstract class AbstractModuleManageCommand extends AbstractModuleCommand
2121
/**
2222
* @var DeploymentConfig
2323
*/
24-
private $deploymentConfig;
24+
protected $deploymentConfig;
2525

2626
/**
2727
* {@inheritdoc}

setup/src/Magento/Setup/Test/Unit/Console/Command/ModuleEnableDisableCommandTest.php

Lines changed: 68 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,52 @@ class ModuleEnableDisableCommandTest extends \PHPUnit_Framework_TestCase
1414
/**
1515
* @var \Magento\Setup\Model\ObjectManagerProvider|\PHPUnit_Framework_MockObject_MockObject
1616
*/
17-
private $objectManagerProvider;
17+
private $objectManagerProviderMock;
1818

1919
/**
2020
* @var \Magento\Framework\Module\Status|\PHPUnit_Framework_MockObject_MockObject
2121
*/
22-
private $status;
22+
private $statusMock;
2323

2424
/**
2525
* @var \Magento\Framework\App\Cache|\PHPUnit_Framework_MockObject_MockObject
2626
*/
27-
private $cache;
27+
private $cacheMock;
2828

2929
/**
3030
* @var \Magento\Framework\App\State\CleanupFiles|\PHPUnit_Framework_MockObject_MockObject
3131
*/
32-
private $cleanupFiles;
32+
private $cleanupFilesMock;
3333

3434
/**
3535
* @var \Magento\Framework\Module\FullModuleList|\PHPUnit_Framework_MockObject_MockObject
3636
*/
37-
private $fullModuleList;
37+
private $fullModuleListMock;
38+
39+
/**
40+
* @var \Magento\Framework\App\DeploymentConfig
41+
*/
42+
private $deploymentConfigMock;
3843

3944
protected function setUp()
4045
{
41-
$this->objectManagerProvider = $this->getMock('Magento\Setup\Model\ObjectManagerProvider', [], [], '', false);
46+
$this->objectManagerProviderMock = $this->getMock('Magento\Setup\Model\ObjectManagerProvider', [], [], '', false);
4247
$objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface');
43-
$this->objectManagerProvider->expects($this->any())
48+
$this->objectManagerProviderMock->expects($this->any())
4449
->method('get')
4550
->will($this->returnValue($objectManager));
46-
$this->status = $this->getMock('Magento\Framework\Module\Status', [], [], '', false);
47-
$this->cache = $this->getMock('Magento\Framework\App\Cache', [], [], '', false);
48-
$this->cleanupFiles = $this->getMock('Magento\Framework\App\State\CleanupFiles', [], [], '', false);
49-
$this->fullModuleList = $this->getMock('Magento\Framework\Module\FullModuleList', [], [], '', false);
51+
$this->statusMock = $this->getMock('Magento\Framework\Module\Status', [], [], '', false);
52+
$this->cacheMock = $this->getMock('Magento\Framework\App\Cache', [], [], '', false);
53+
$this->cleanupFilesMock = $this->getMock('Magento\Framework\App\State\CleanupFiles', [], [], '', false);
54+
$this->fullModuleListMock = $this->getMock('Magento\Framework\Module\FullModuleList', [], [], '', false);
55+
$this->deploymentConfigMock = $this->getMock(\Magento\Framework\App\DeploymentConfig::class, [], [], '', false);
5056
$objectManager->expects($this->any())
5157
->method('get')
5258
->will($this->returnValueMap([
53-
['Magento\Framework\Module\Status', $this->status],
54-
['Magento\Framework\App\Cache', $this->cache],
55-
['Magento\Framework\App\State\CleanupFiles', $this->cleanupFiles],
56-
['Magento\Framework\Module\FullModuleList', $this->fullModuleList],
59+
['Magento\Framework\Module\Status', $this->statusMock],
60+
['Magento\Framework\App\Cache', $this->cacheMock],
61+
['Magento\Framework\App\State\CleanupFiles', $this->cleanupFilesMock],
62+
['Magento\Framework\Module\FullModuleList', $this->fullModuleListMock],
5763
]));
5864
}
5965

@@ -66,29 +72,23 @@ protected function setUp()
6672
*/
6773
public function testExecute($isEnable, $clearStaticContent, $expectedMessage)
6874
{
69-
$this->status->expects($this->once())
75+
$this->statusMock->expects($this->once())
7076
->method('getModulesToChange')
7177
->with($isEnable, ['Magento_Module1', 'Magento_Module2'])
7278
->will($this->returnValue(['Magento_Module1']));
73-
74-
$this->status->expects($this->any())
79+
$this->statusMock->expects($this->any())
7580
->method('checkConstraints')
7681
->will($this->returnValue([]));
77-
78-
$this->status->expects($this->once())
82+
$this->statusMock->expects($this->once())
7983
->method('setIsEnabled')
8084
->with($isEnable, ['Magento_Module1']);
81-
82-
$this->cache->expects($this->once())
85+
$this->cacheMock->expects($this->once())
8386
->method('clean');
84-
$this->cleanupFiles->expects($this->once())
87+
$this->cleanupFilesMock->expects($this->once())
8588
->method('clearCodeGeneratedClasses');
86-
$this->cleanupFiles->expects($clearStaticContent ? $this->once() : $this->never())
89+
$this->cleanupFilesMock->expects($clearStaticContent ? $this->once() : $this->never())
8790
->method('clearMaterializedViewFiles');
88-
89-
$commandTester = $isEnable
90-
? new CommandTester(new ModuleEnableCommand($this->objectManagerProvider))
91-
: new CommandTester(new ModuleDisableCommand($this->objectManagerProvider));
91+
$commandTester = $this->getCommandTester($isEnable);
9292
$input = ['module' => ['Magento_Module1', 'Magento_Module2']];
9393
if ($clearStaticContent) {
9494
$input['--clear-static-content'] = true;
@@ -106,14 +106,14 @@ public function executeDataProvider()
106106
'enable, do not clear static content' => [
107107
true,
108108
false,
109-
'%amodules have been enabled%aMagento_Module1%a' .
110-
'Info: Some modules might require static view files to be cleared.%a'
109+
'%amodules have been enabled%aMagento_Module1%a'
110+
. 'Info: Some modules might require static view files to be cleared.%a'
111111
],
112112
'disable, do not clear static content' => [
113113
false,
114114
false,
115-
'%amodules have been disabled%aMagento_Module1%a' .
116-
'Info: Some modules might require static view files to be cleared.%a'
115+
'%amodules have been disabled%aMagento_Module1%a'
116+
. 'Info: Some modules might require static view files to be cleared.%a'
117117
],
118118
'enable, clear static content' => [
119119
true,
@@ -124,29 +124,29 @@ public function executeDataProvider()
124124
false,
125125
true,
126126
'%amodules have been disabled%aMagento_Module1%aGenerated static view files cleared%a'
127-
],
127+
]
128128
];
129129
}
130130

131131
public function testExecuteEnableInvalidModule()
132132
{
133-
$this->status->expects($this->once())
133+
$this->statusMock->expects($this->once())
134134
->method('getModulesToChange')
135135
->with(true, ['invalid'])
136136
->willThrowException(new \LogicException('Unknown module(s): invalid'));
137-
$commandTester = new CommandTester(new ModuleEnableCommand($this->objectManagerProvider));
137+
$commandTester = $this->getCommandTester(true);
138138
$input = ['module' => ['invalid']];
139139
$commandTester->execute($input);
140140
$this->assertEquals('Unknown module(s): invalid' . PHP_EOL, $commandTester->getDisplay());
141141
}
142142

143143
public function testExecuteDisableInvalidModule()
144144
{
145-
$this->status->expects($this->once())
145+
$this->statusMock->expects($this->once())
146146
->method('getModulesToChange')
147147
->with(false, ['invalid'])
148148
->willThrowException(new \LogicException('Unknown module(s): invalid'));
149-
$commandTester = new CommandTester(new ModuleDisableCommand($this->objectManagerProvider));
149+
$commandTester = $this->getCommandTester(false);
150150
$input = ['module' => ['invalid']];
151151
$commandTester->execute($input);
152152
$this->assertEquals('Unknown module(s): invalid' . PHP_EOL, $commandTester->getDisplay());
@@ -155,31 +155,26 @@ public function testExecuteDisableInvalidModule()
155155
/**
156156
* @param bool $isEnable
157157
* @param string $expectedMessage
158+
* @param bool $isInstalled
158159
*
159160
* @dataProvider executeAllDataProvider
160161
*/
161162
public function testExecuteAll($isEnable, $expectedMessage)
162163
{
163-
$this->fullModuleList->expects($this->once())
164+
$this->fullModuleListMock->expects($this->once())
164165
->method('getNames')
165166
->will($this->returnValue(['Magento_Module1', 'Magento_Module2']));
166-
167-
$this->status->expects($this->once())
167+
$this->statusMock->expects($this->once())
168168
->method('getModulesToChange')
169169
->with($isEnable, ['Magento_Module1', 'Magento_Module2'])
170170
->will($this->returnValue(['Magento_Module1']));
171-
172-
$this->status->expects($this->any())
171+
$this->statusMock->expects($this->any())
173172
->method('checkConstraints')
174173
->will($this->returnValue([]));
175-
176-
$this->status->expects($this->once())
174+
$this->statusMock->expects($this->once())
177175
->method('setIsEnabled')
178176
->with($isEnable, ['Magento_Module1']);
179-
180-
$commandTester = $isEnable
181-
? new CommandTester(new ModuleEnableCommand($this->objectManagerProvider))
182-
: new CommandTester(new ModuleDisableCommand($this->objectManagerProvider));
177+
$commandTester = $this->getCommandTester($isEnable);
183178
$input = ['--all' => true];
184179
$commandTester->execute($input);
185180
$this->assertStringMatchesFormat($expectedMessage, $commandTester->getDisplay());
@@ -203,21 +198,16 @@ public function executeAllDataProvider()
203198
*/
204199
public function testExecuteWithConstraints($isEnable)
205200
{
206-
$this->status->expects($this->once())
201+
$this->statusMock->expects($this->once())
207202
->method('getModulesToChange')
208203
->with($isEnable, ['Magento_Module1', 'Magento_Module2'])
209204
->will($this->returnValue(['Magento_Module1']));
210-
211-
$this->status->expects($this->any())
205+
$this->statusMock->expects($this->any())
212206
->method('checkConstraints')
213207
->will($this->returnValue(['constraint1', 'constraint2']));
214-
215-
$this->status->expects($this->never())
208+
$this->statusMock->expects($this->never())
216209
->method('setIsEnabled');
217-
218-
$commandTester = $isEnable
219-
? new CommandTester(new ModuleEnableCommand($this->objectManagerProvider))
220-
: new CommandTester(new ModuleDisableCommand($this->objectManagerProvider));
210+
$commandTester = $this->getCommandTester($isEnable);
221211
$commandTester->execute(['module' => ['Magento_Module1', 'Magento_Module2']]);
222212
$this->assertStringMatchesFormat(
223213
'Unable to change status of modules%aconstraint1%aconstraint2%a',
@@ -244,21 +234,16 @@ public function executeWithConstraintsDataProvider()
244234
*/
245235
public function testExecuteForce($isEnable, $expectedMessage)
246236
{
247-
$this->status->expects($this->once())
237+
$this->statusMock->expects($this->once())
248238
->method('getModulesToChange')
249239
->with($isEnable, ['Magento_Module1', 'Magento_Module2'])
250240
->will($this->returnValue(['Magento_Module1']));
251-
252-
$this->status->expects($this->never())
241+
$this->statusMock->expects($this->never())
253242
->method('checkConstraints');
254-
255-
$this->status->expects($this->once())
243+
$this->statusMock->expects($this->once())
256244
->method('setIsEnabled')
257245
->with($isEnable, ['Magento_Module1']);
258-
259-
$commandTester = $isEnable
260-
? new CommandTester(new ModuleEnableCommand($this->objectManagerProvider))
261-
: new CommandTester(new ModuleDisableCommand($this->objectManagerProvider));
246+
$commandTester = $this->getCommandTester($isEnable);
262247
$commandTester->execute(['module' => ['Magento_Module1', 'Magento_Module2'], '--force' => true]);
263248
$this->assertStringMatchesFormat(
264249
$expectedMessage . '%amodules might not function properly%a',
@@ -284,21 +269,31 @@ public function executeExecuteForceDataProvider()
284269
*/
285270
public function testExecuteNoChanges($isEnable)
286271
{
287-
$this->status->expects($this->once())
272+
$this->statusMock->expects($this->once())
288273
->method('getModulesToChange')
289274
->with($isEnable, ['Magento_Module1', 'Magento_Module2'])
290275
->will($this->returnValue([]));
291-
292-
$this->status->expects($this->never())
276+
$this->statusMock->expects($this->never())
293277
->method('setIsEnabled');
294-
295-
$commandTester = $isEnable
296-
? new CommandTester(new ModuleEnableCommand($this->objectManagerProvider))
297-
: new CommandTester(new ModuleDisableCommand($this->objectManagerProvider));
278+
$commandTester = $this->getCommandTester($isEnable);
298279
$commandTester->execute(['module' => ['Magento_Module1', 'Magento_Module2']]);
299280
$this->assertStringMatchesFormat(
300281
'No modules were changed%a',
301282
$commandTester->getDisplay()
302283
);
303284
}
285+
286+
/**
287+
* @param bool $isEnable
288+
* @return CommandTester
289+
*/
290+
private function getCommandTester($isEnable)
291+
{
292+
$class = $isEnable ? ModuleEnableCommand::class : ModuleDisableCommand::class;
293+
$command = new $class($this->objectManagerProviderMock);
294+
$deploymentConfigProperty = new \ReflectionProperty($class, 'deploymentConfig');
295+
$deploymentConfigProperty->setAccessible(true);
296+
$deploymentConfigProperty->setValue($command, $this->deploymentConfigMock);
297+
return new CommandTester($command);
298+
}
304299
}

0 commit comments

Comments
 (0)