1212class 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,87 @@ 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
96- public function testExecuteDiExists ()
96+ public function testExecuteModulesNotEnabled ()
9797 {
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 );
111103 $ tester = new CommandTester ($ this ->command );
112104 $ tester ->execute ([]);
113105 $ 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 ,
115108 $ tester ->getDisplay ()
116109 );
117110 }
118111
119112 public function testExecute ()
120113 {
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 ())
123116 ->method ('get ' )
124117 ->with ('Magento\Framework\App\Cache ' )
125118 ->willReturn ($ this ->cacheMock );
126119 $ this ->cacheMock ->expects ($ this ->once ())->method ('clean ' );
127120 $ writeDirectory = $ this ->getMock ('Magento\Framework\Filesystem\Directory\WriteInterface ' );
128121 $ 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 );
130123
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 ]);
132128 $ progressBar = $ this ->getMockBuilder (
133129 'Symfony\Component\Console\Helper\ProgressBar '
134130 )
135131 ->disableOriginalConstructor ()
136132 ->getMock ();
137133
138- $ this ->objectManager ->expects ($ this ->once ())->method ('configure ' );
139- $ this ->objectManager
134+ $ this ->objectManagerMock ->expects ($ this ->once ())->method ('configure ' );
135+ $ this ->objectManagerMock
140136 ->expects ($ this ->once ())
141137 ->method ('create ' )
142138 ->with ('Symfony\Component\Console\Helper\ProgressBar ' )
143139 ->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 ' );
146142 $ tester = new CommandTester ($ this ->command );
147143 $ tester ->execute ([]);
148144 $ this ->assertContains (
0 commit comments