Skip to content

Commit 401aba3

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

File tree

1 file changed

+52
-42
lines changed

1 file changed

+52
-42
lines changed

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

Lines changed: 52 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
class DiCompileCommandTest extends \PHPUnit_Framework_TestCase
1313
{
1414
/** @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject */
15-
private $deploymentConfig;
15+
private $deploymentConfigMock;
1616

1717
/** @var \Magento\Setup\Module\Di\App\Task\Manager|\PHPUnit_Framework_MockObject_MockObject */
18-
private $manager;
18+
private $managerMock;
1919

2020
/** @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
21-
private $objectManager;
21+
private $objectManagerMock;
2222

2323
/** @var DiCompileCommand|\PHPUnit_Framework_MockObject_MockObject */
2424
private $command;
@@ -27,28 +27,28 @@ class DiCompileCommandTest extends \PHPUnit_Framework_TestCase
2727
private $cacheMock;
2828

2929
/** @var \Magento\Framework\Filesystem|\PHPUnit_Framework_MockObject_MockObject */
30-
private $filesystem;
30+
private $filesystemMock;
3131

32-
/** @var \Magento\Framework\Filesystem\Driver\File | \PHPUnit_Framework_MockObject_MockObject*/
33-
private $fileDriver;
32+
/** @var \Magento\Framework\Filesystem\Driver\File|\PHPUnit_Framework_MockObject_MockObject */
33+
private $fileDriverMock;
3434

35-
/** @var \Magento\Framework\App\Filesystem\DirectoryList | \PHPUnit_Framework_MockObject_MockObject*/
36-
private $directoryList;
35+
/** @var \Magento\Framework\App\Filesystem\DirectoryList|\PHPUnit_Framework_MockObject_MockObject */
36+
private $directoryListMock;
3737

3838
/** @var \Magento\Framework\Component\ComponentRegistrar|\PHPUnit_Framework_MockObject_MockObject */
39-
private $componentRegistrar;
39+
private $componentRegistrarMock;
4040

4141
public function setUp()
4242
{
43-
$this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false);
44-
$objectManagerProvider = $this->getMock(
43+
$this->deploymentConfigMock = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false);
44+
$objectManagerProviderMock = $this->getMock(
4545
'Magento\Setup\Model\ObjectManagerProvider',
4646
[],
4747
[],
4848
'',
4949
false
5050
);
51-
$this->objectManager = $this->getMockForAbstractClass(
51+
$this->objectManagerMock = $this->getMockForAbstractClass(
5252
'Magento\Framework\ObjectManagerInterface',
5353
[],
5454
'',
@@ -58,91 +58,101 @@ public function setUp()
5858
->disableOriginalConstructor()
5959
->getMock();
6060

61-
$objectManagerProvider->expects($this->once())
61+
$objectManagerProviderMock->expects($this->once())
6262
->method('get')
63-
->willReturn($this->objectManager);
64-
$this->manager = $this->getMock('Magento\Setup\Module\Di\App\Task\Manager', [], [], '', false);
65-
$this->directoryList = $this->getMock('Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false);
66-
$this->filesystem = $this->getMockBuilder('Magento\Framework\Filesystem')
63+
->willReturn($this->objectManagerMock);
64+
$this->managerMock = $this->getMock('Magento\Setup\Module\Di\App\Task\Manager', [], [], '', false);
65+
$this->directoryListMock = $this->getMock('Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false);
66+
$this->filesystemMock = $this->getMockBuilder('Magento\Framework\Filesystem')
6767
->disableOriginalConstructor()
6868
->getMock();
6969

70-
$this->fileDriver = $this->getMockBuilder('Magento\Framework\Filesystem\Driver\File')
70+
$this->fileDriverMock = $this->getMockBuilder('Magento\Framework\Filesystem\Driver\File')
7171
->disableOriginalConstructor()
7272
->getMock();
73-
$this->componentRegistrar = $this->getMock(
73+
$this->componentRegistrarMock = $this->getMock(
7474
'\Magento\Framework\Component\ComponentRegistrar',
7575
[],
7676
[],
7777
'',
7878
false
7979
);
80-
$this->componentRegistrar->expects($this->any())->method('getPaths')->willReturnMap([
80+
$this->componentRegistrarMock->expects($this->any())->method('getPaths')->willReturnMap([
8181
[ComponentRegistrar::MODULE, ['/path/to/module/one', '/path/to/module/two']],
8282
[ComponentRegistrar::LIBRARY, ['/path/to/library/one', '/path/to/library/two']],
8383
]);
8484

8585
$this->command = new DiCompileCommand(
86-
$this->deploymentConfig,
87-
$this->directoryList,
88-
$this->manager,
89-
$objectManagerProvider,
90-
$this->filesystem,
91-
$this->fileDriver,
92-
$this->componentRegistrar
86+
$this->deploymentConfigMock,
87+
$this->directoryListMock,
88+
$this->managerMock,
89+
$objectManagerProviderMock,
90+
$this->filesystemMock,
91+
$this->fileDriverMock,
92+
$this->componentRegistrarMock
9393
);
9494
}
9595

9696
public function testExecuteDiExists()
9797
{
9898
$diPath = '/root/magento/var/di';
99-
$this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(true);
100-
$this->fileDriver->expects($this->atLeastOnce())->method('isExists')->with($diPath)->willReturn(true);
101-
$this->directoryList->expects($this->atLeastOnce())->method('getPath')->willReturn($diPath);
99+
$this->deploymentConfigMock->expects($this->once())
100+
->method('get')
101+
->with(\Magento\Framework\Config\ConfigOptionsListConstants::KEY_MODULES)
102+
->willReturn(['Magento_Catalog' => 1]);
103+
$this->fileDriverMock->expects($this->atLeastOnce())->method('isExists')->with($diPath)->willReturn(true);
104+
$this->directoryListMock->expects($this->atLeastOnce())->method('getPath')->willReturn($diPath);
102105
$tester = new CommandTester($this->command);
103106
$tester->execute([]);
104107
$this->assertContains("delete '/root/magento/var/di'", $tester->getDisplay());
105108
}
106109

107-
public function testExecuteNotInstalled()
110+
public function testExecuteModulesNotEnabled()
108111
{
109-
$this->directoryList->expects($this->atLeastOnce())->method('getPath')->willReturn(null);
110-
$this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(false);
112+
$this->directoryListMock->expects($this->atLeastOnce())->method('getPath')->willReturn(null);
113+
$this->deploymentConfigMock->expects($this->once())
114+
->method('get')
115+
->with(\Magento\Framework\Config\ConfigOptionsListConstants::KEY_MODULES)
116+
->willReturn(null);
111117
$tester = new CommandTester($this->command);
112118
$tester->execute([]);
113119
$this->assertEquals(
114-
'You cannot run this command because the Magento application is not installed.' . PHP_EOL,
120+
'You cannot run this command because modules are not enabled. You can enable modules by running \'module:'
121+
. 'enable --all\' command.' . PHP_EOL,
115122
$tester->getDisplay()
116123
);
117124
}
118125

119126
public function testExecute()
120127
{
121-
$this->directoryList->expects($this->atLeastOnce())->method('getPath')->willReturn(null);
122-
$this->objectManager->expects($this->once())
128+
$this->directoryListMock->expects($this->atLeastOnce())->method('getPath')->willReturn(null);
129+
$this->objectManagerMock->expects($this->once())
123130
->method('get')
124131
->with('Magento\Framework\App\Cache')
125132
->willReturn($this->cacheMock);
126133
$this->cacheMock->expects($this->once())->method('clean');
127134
$writeDirectory = $this->getMock('Magento\Framework\Filesystem\Directory\WriteInterface');
128135
$writeDirectory->expects($this->atLeastOnce())->method('delete');
129-
$this->filesystem->expects($this->atLeastOnce())->method('getDirectoryWrite')->willReturn($writeDirectory);
136+
$this->filesystemMock->expects($this->atLeastOnce())->method('getDirectoryWrite')->willReturn($writeDirectory);
130137

131-
$this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(true);
138+
$this->deploymentConfigMock->expects($this->once())
139+
->method('get')
140+
->with(\Magento\Framework\Config\ConfigOptionsListConstants::KEY_MODULES)
141+
->willReturn(['Magento_Catalog' => 1]);
132142
$progressBar = $this->getMockBuilder(
133143
'Symfony\Component\Console\Helper\ProgressBar'
134144
)
135145
->disableOriginalConstructor()
136146
->getMock();
137147

138-
$this->objectManager->expects($this->once())->method('configure');
139-
$this->objectManager
148+
$this->objectManagerMock->expects($this->once())->method('configure');
149+
$this->objectManagerMock
140150
->expects($this->once())
141151
->method('create')
142152
->with('Symfony\Component\Console\Helper\ProgressBar')
143153
->willReturn($progressBar);
144-
$this->manager->expects($this->exactly(7))->method('addOperation');
145-
$this->manager->expects($this->once())->method('process');
154+
$this->managerMock->expects($this->exactly(7))->method('addOperation');
155+
$this->managerMock->expects($this->once())->method('process');
146156
$tester = new CommandTester($this->command);
147157
$tester->execute([]);
148158
$this->assertContains(

0 commit comments

Comments
 (0)