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,87 @@ 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
- public function testExecuteDiExists ()
96
+ public function testExecuteModulesNotEnabled ()
97
97
{
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 );
102
- $ tester = new CommandTester ($ this ->command );
103
- $ tester ->execute ([]);
104
- $ this ->assertContains ("delete '/root/magento/var/di' " , $ tester ->getDisplay ());
105
- }
106
-
107
- public function testExecuteNotInstalled ()
108
- {
109
- $ this ->directoryList ->expects ($ this ->atLeastOnce ())->method ('getPath ' )->willReturn (null );
110
- $ this ->deploymentConfig ->expects ($ this ->once ())->method ('isAvailable ' )->willReturn (false );
98
+ $ this ->directoryListMock ->expects ($ this ->atLeastOnce ())->method ('getPath ' )->willReturn (null );
99
+ $ this ->deploymentConfigMock ->expects ($ this ->once ())
100
+ ->method ('get ' )
101
+ ->with (\Magento \Framework \Config \ConfigOptionsListConstants::KEY_MODULES )
102
+ ->willReturn (null );
111
103
$ tester = new CommandTester ($ this ->command );
112
104
$ tester ->execute ([]);
113
105
$ this ->assertEquals (
114
- 'You cannot run this command because the Magento application is not installed. ' . PHP_EOL ,
106
+ 'You cannot run this command because modules are not enabled. You can enable modules by running the '
107
+ . "'module:enable --all' command. " . PHP_EOL ,
115
108
$ tester ->getDisplay ()
116
109
);
117
110
}
118
111
119
112
public function testExecute ()
120
113
{
121
- $ this ->directoryList ->expects ($ this ->atLeastOnce ())->method ('getPath ' )->willReturn (null );
122
- $ this ->objectManager ->expects ($ this ->once ())
114
+ $ this ->directoryListMock ->expects ($ this ->atLeastOnce ())->method ('getPath ' )->willReturn (null );
115
+ $ this ->objectManagerMock ->expects ($ this ->once ())
123
116
->method ('get ' )
124
117
->with ('Magento\Framework\App\Cache ' )
125
118
->willReturn ($ this ->cacheMock );
126
119
$ this ->cacheMock ->expects ($ this ->once ())->method ('clean ' );
127
120
$ writeDirectory = $ this ->getMock ('Magento\Framework\Filesystem\Directory\WriteInterface ' );
128
121
$ writeDirectory ->expects ($ this ->atLeastOnce ())->method ('delete ' );
129
- $ this ->filesystem ->expects ($ this ->atLeastOnce ())->method ('getDirectoryWrite ' )->willReturn ($ writeDirectory );
122
+ $ this ->filesystemMock ->expects ($ this ->atLeastOnce ())->method ('getDirectoryWrite ' )->willReturn ($ writeDirectory );
130
123
131
- $ this ->deploymentConfig ->expects ($ this ->once ())->method ('isAvailable ' )->willReturn (true );
124
+ $ this ->deploymentConfigMock ->expects ($ this ->once ())
125
+ ->method ('get ' )
126
+ ->with (\Magento \Framework \Config \ConfigOptionsListConstants::KEY_MODULES )
127
+ ->willReturn (['Magento_Catalog ' => 1 ]);
132
128
$ progressBar = $ this ->getMockBuilder (
133
129
'Symfony\Component\Console\Helper\ProgressBar '
134
130
)
135
131
->disableOriginalConstructor ()
136
132
->getMock ();
137
133
138
- $ this ->objectManager ->expects ($ this ->once ())->method ('configure ' );
139
- $ this ->objectManager
134
+ $ this ->objectManagerMock ->expects ($ this ->once ())->method ('configure ' );
135
+ $ this ->objectManagerMock
140
136
->expects ($ this ->once ())
141
137
->method ('create ' )
142
138
->with ('Symfony\Component\Console\Helper\ProgressBar ' )
143
139
->willReturn ($ progressBar );
144
- $ this ->manager ->expects ($ this ->exactly (7 ))->method ('addOperation ' );
145
- $ this ->manager ->expects ($ this ->once ())->method ('process ' );
140
+ $ this ->managerMock ->expects ($ this ->exactly (7 ))->method ('addOperation ' );
141
+ $ this ->managerMock ->expects ($ this ->once ())->method ('process ' );
146
142
$ tester = new CommandTester ($ this ->command );
147
143
$ tester ->execute ([]);
148
144
$ this ->assertContains (
0 commit comments