66namespace Magento \TestFramework \Deploy ;
77
88use Magento \Framework \App \DeploymentConfig ;
9+ use Magento \Framework \Exception \LocalizedException ;
910use Magento \Framework \Shell ;
1011use Magento \Framework \Shell \CommandRenderer ;
1112use Magento \Setup \Console \Command \InstallCommand ;
1213
1314/**
1415 * The purpose of this class is enable/disable module and upgrade commands execution.
16+ *
17+ * @SuppressWarnings(PHPMD.TooManyPublicMethods)
1518 */
1619class CliCommand
1720{
1821 /**
19- * @var \Magento\Framework\ Shell
22+ * @var Shell
2023 */
2124 private $ shell ;
2225
@@ -36,10 +39,7 @@ class CliCommand
3639 private $ deploymentConfig ;
3740
3841 /**
39- * ShellCommand constructor.
40- *
41- * @param TestModuleManager $testEnv
42- * @param DeploymentConfig $deploymentConfig
42+ * @param TestModuleManager $testEnv
4343 * @internal param Shell $shell
4444 */
4545 public function __construct (
@@ -53,8 +53,9 @@ public function __construct(
5353 /**
5454 * Copy Test module files and execute enable module command.
5555 *
56- * @param string $moduleName
56+ * @param string $moduleName
5757 * @return string
58+ * @throws LocalizedException
5859 */
5960 public function introduceModule ($ moduleName )
6061 {
@@ -65,13 +66,14 @@ public function introduceModule($moduleName)
6566 /**
6667 * Execute enable module command.
6768 *
68- * @param string $moduleName
69+ * @param string $moduleName
6970 * @return string
71+ * @throws LocalizedException
7072 */
7173 public function enableModule ($ moduleName )
7274 {
7375 $ initParams = $ this ->parametersHolder ->getInitParams ();
74- $ enableModuleCommand = ' php -f ' . BP . ' /bin/magento module:enable ' . $ moduleName
76+ $ enableModuleCommand = $ this -> getCliScriptCommand () . ' module:enable ' . $ moduleName
7577 . ' -n -vvv --magento-init-params=" ' . $ initParams ['magento-init-params ' ] . '" ' ;
7678 return $ this ->shell ->execute ($ enableModuleCommand );
7779 }
@@ -81,11 +83,12 @@ public function enableModule($moduleName)
8183 *
8284 * @param array $installParams
8385 * @return string
86+ * @throws LocalizedException
8487 */
8588 public function upgrade ($ installParams = [])
8689 {
8790 $ initParams = $ this ->parametersHolder ->getInitParams ();
88- $ upgradeCommand = ' php -f ' . BP . ' /bin/magento setup:upgrade -vvv -n --magento-init-params=" '
91+ $ upgradeCommand = $ this -> getCliScriptCommandWithDI () . ' setup:upgrade -vvv -n --magento-init-params=" '
8992 . $ initParams ['magento-init-params ' ] . '" ' ;
9093 $ installParams = $ this ->toCliArguments ($ installParams );
9194 $ upgradeCommand .= ' ' . implode (" " , array_keys ($ installParams ));
@@ -96,13 +99,14 @@ public function upgrade($installParams = [])
9699 /**
97100 * Execute disable module command.
98101 *
99- * @param string $moduleName
102+ * @param string $moduleName
100103 * @return string
104+ * @throws LocalizedException
101105 */
102106 public function disableModule ($ moduleName )
103107 {
104108 $ initParams = $ this ->parametersHolder ->getInitParams ();
105- $ disableModuleCommand = ' php -f ' . BP . ' /bin/magento module:disable ' . $ moduleName
109+ $ disableModuleCommand = $ this -> getCliScriptCommand () . ' module:disable ' . $ moduleName
106110 . ' -vvv --magento-init-params=" ' . $ initParams ['magento-init-params ' ] . '" ' ;
107111 return $ this ->shell ->execute ($ disableModuleCommand );
108112 }
@@ -111,14 +115,15 @@ public function disableModule($moduleName)
111115 * Split quote db configuration.
112116 *
113117 * @return void
118+ * @throws LocalizedException
114119 */
115120 public function splitQuote ()
116121 {
117122 $ initParams = $ this ->parametersHolder ->getInitParams ();
118123 $ installParams = $ this ->toCliArguments (
119124 $ this ->parametersHolder ->getDbData ('checkout ' )
120125 );
121- $ command = ' php -f ' . BP . ' /bin/magento setup:db-schema:split-quote ' .
126+ $ command = $ this -> getCliScriptCommand () . ' setup:db-schema:split-quote ' .
122127 implode (" " , array_keys ($ installParams )) .
123128 ' -vvv --magento-init-params=" ' .
124129 $ initParams ['magento-init-params ' ] . '" ' ;
@@ -130,14 +135,15 @@ public function splitQuote()
130135 * Split sales db configuration.
131136 *
132137 * @return void
138+ * @throws LocalizedException
133139 */
134140 public function splitSales ()
135141 {
136142 $ initParams = $ this ->parametersHolder ->getInitParams ();
137143 $ installParams = $ this ->toCliArguments (
138144 $ this ->parametersHolder ->getDbData ('sales ' )
139145 );
140- $ command = ' php -f ' . BP . ' /bin/magento setup:db-schema:split-sales ' .
146+ $ command = $ this -> getCliScriptCommand () . ' setup:db-schema:split-sales ' .
141147 implode (" " , array_keys ($ installParams )) .
142148 ' -vvv --magento-init-params=" ' .
143149 $ initParams ['magento-init-params ' ] . '" ' ;
@@ -151,7 +157,7 @@ public function splitSales()
151157 public function cacheClean ()
152158 {
153159 $ initParams = $ this ->parametersHolder ->getInitParams ();
154- $ command = ' php -f ' . BP . ' /bin/magento cache:clean ' .
160+ $ command = $ this -> getCliScriptCommand () . ' cache:clean ' .
155161 ' -vvv --magento-init-params= ' .
156162 $ initParams ['magento-init-params ' ];
157163
@@ -162,11 +168,12 @@ public function cacheClean()
162168 * Uninstall module
163169 *
164170 * @param string $moduleName
171+ * @throws LocalizedException
165172 */
166173 public function uninstallModule ($ moduleName )
167174 {
168175 $ initParams = $ this ->parametersHolder ->getInitParams ();
169- $ command = ' php -f ' . BP . ' /bin/magento module:uninstall ' . $ moduleName . ' --remove-data ' .
176+ $ command = $ this -> getCliScriptCommand () . ' module:uninstall ' . $ moduleName . ' --remove-data ' .
170177 ' -vvv --non-composer --magento-init-params=" ' .
171178 $ initParams ['magento-init-params ' ] . '" ' ;
172179
@@ -240,4 +247,29 @@ public function afterInstall()
240247 ->get (DeploymentConfig::class);
241248 $ this ->deploymentConfig ->resetData ();
242249 }
250+
251+ /**
252+ * Get custom magento-cli command with additional DI configuration
253+ *
254+ * @return string
255+ */
256+ private function getCliScriptCommandWithDI (): string
257+ {
258+ $ params ['MAGE_DIRS ' ]['base ' ]['path ' ] = BP ;
259+ $ params ['INTEGRATION_TESTS_CLI_AUTOLOADER ' ] = TESTS_BASE_DIR . '/framework/autoload.php ' ;
260+ $ params ['TESTS_BASE_DIR ' ] = TESTS_BASE_DIR ;
261+ return 'INTEGRATION_TEST_PARAMS=" ' . urldecode (http_build_query ($ params )) . '" '
262+ . ' ' . PHP_BINARY . ' -f ' . INTEGRATION_TESTS_BASE_DIR
263+ . '/bin/magento ' ;
264+ }
265+
266+ /**
267+ * Get basic magento-cli command
268+ *
269+ * @return string
270+ */
271+ private function getCliScriptCommand ()
272+ {
273+ return PHP_BINARY . ' -f ' . BP . '/bin/magento ' ;
274+ }
243275}
0 commit comments