12
12
class DiCompileCommandTest extends \PHPUnit_Framework_TestCase
13
13
{
14
14
/** @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject */
15
- private $ deploymentConfig ;
15
+ private $ deploymentConfigMock ;
16
16
17
17
/** @var \Magento\Setup\Module\Di\App\Task\Manager|\PHPUnit_Framework_MockObject_MockObject */
18
- private $ manager ;
18
+ private $ managerMock ;
19
19
20
20
/** @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
21
- private $ objectManager ;
21
+ private $ objectManagerMock ;
22
22
23
23
/** @var DiCompileCommand|\PHPUnit_Framework_MockObject_MockObject */
24
24
private $ command ;
@@ -27,28 +27,28 @@ class DiCompileCommandTest extends \PHPUnit_Framework_TestCase
27
27
private $ cacheMock ;
28
28
29
29
/** @var \Magento\Framework\Filesystem|\PHPUnit_Framework_MockObject_MockObject */
30
- private $ filesystem ;
30
+ private $ filesystemMock ;
31
31
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 ;
34
34
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 ;
37
37
38
38
/** @var \Magento\Framework\Component\ComponentRegistrar|\PHPUnit_Framework_MockObject_MockObject */
39
- private $ componentRegistrar ;
39
+ private $ componentRegistrarMock ;
40
40
41
41
public function setUp ()
42
42
{
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 (
45
45
'Magento\Setup\Model\ObjectManagerProvider ' ,
46
46
[],
47
47
[],
48
48
'' ,
49
49
false
50
50
);
51
- $ this ->objectManager = $ this ->getMockForAbstractClass (
51
+ $ this ->objectManagerMock = $ this ->getMockForAbstractClass (
52
52
'Magento\Framework\ObjectManagerInterface ' ,
53
53
[],
54
54
'' ,
@@ -58,91 +58,101 @@ public function setUp()
58
58
->disableOriginalConstructor ()
59
59
->getMock ();
60
60
61
- $ objectManagerProvider ->expects ($ this ->once ())
61
+ $ objectManagerProviderMock ->expects ($ this ->once ())
62
62
->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 ' )
67
67
->disableOriginalConstructor ()
68
68
->getMock ();
69
69
70
- $ this ->fileDriver = $ this ->getMockBuilder ('Magento\Framework\Filesystem\Driver\File ' )
70
+ $ this ->fileDriverMock = $ this ->getMockBuilder ('Magento\Framework\Filesystem\Driver\File ' )
71
71
->disableOriginalConstructor ()
72
72
->getMock ();
73
- $ this ->componentRegistrar = $ this ->getMock (
73
+ $ this ->componentRegistrarMock = $ this ->getMock (
74
74
'\Magento\Framework\Component\ComponentRegistrar ' ,
75
75
[],
76
76
[],
77
77
'' ,
78
78
false
79
79
);
80
- $ this ->componentRegistrar ->expects ($ this ->any ())->method ('getPaths ' )->willReturnMap ([
80
+ $ this ->componentRegistrarMock ->expects ($ this ->any ())->method ('getPaths ' )->willReturnMap ([
81
81
[ComponentRegistrar::MODULE , ['/path/to/module/one ' , '/path/to/module/two ' ]],
82
82
[ComponentRegistrar::LIBRARY , ['/path/to/library/one ' , '/path/to/library/two ' ]],
83
83
]);
84
84
85
85
$ 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
93
93
);
94
94
}
95
95
96
96
public function testExecuteDiExists ()
97
97
{
98
98
$ 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 );
102
105
$ tester = new CommandTester ($ this ->command );
103
106
$ tester ->execute ([]);
104
107
$ this ->assertContains ("delete '/root/magento/var/di' " , $ tester ->getDisplay ());
105
108
}
106
109
107
- public function testExecuteNotInstalled ()
110
+ public function testExecuteModulesNotEnabled ()
108
111
{
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 );
111
117
$ tester = new CommandTester ($ this ->command );
112
118
$ tester ->execute ([]);
113
119
$ 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 ,
115
122
$ tester ->getDisplay ()
116
123
);
117
124
}
118
125
119
126
public function testExecute ()
120
127
{
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 ())
123
130
->method ('get ' )
124
131
->with ('Magento\Framework\App\Cache ' )
125
132
->willReturn ($ this ->cacheMock );
126
133
$ this ->cacheMock ->expects ($ this ->once ())->method ('clean ' );
127
134
$ writeDirectory = $ this ->getMock ('Magento\Framework\Filesystem\Directory\WriteInterface ' );
128
135
$ 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 );
130
137
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 ]);
132
142
$ progressBar = $ this ->getMockBuilder (
133
143
'Symfony\Component\Console\Helper\ProgressBar '
134
144
)
135
145
->disableOriginalConstructor ()
136
146
->getMock ();
137
147
138
- $ this ->objectManager ->expects ($ this ->once ())->method ('configure ' );
139
- $ this ->objectManager
148
+ $ this ->objectManagerMock ->expects ($ this ->once ())->method ('configure ' );
149
+ $ this ->objectManagerMock
140
150
->expects ($ this ->once ())
141
151
->method ('create ' )
142
152
->with ('Symfony\Component\Console\Helper\ProgressBar ' )
143
153
->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 ' );
146
156
$ tester = new CommandTester ($ this ->command );
147
157
$ tester ->execute ([]);
148
158
$ this ->assertContains (
0 commit comments