6
6
namespace Magento \TestFramework \Deploy ;
7
7
8
8
use Magento \Framework \App \DeploymentConfig ;
9
+ use Magento \Framework \Exception \LocalizedException ;
9
10
use Magento \Framework \Shell ;
10
11
use Magento \Framework \Shell \CommandRenderer ;
11
12
use Magento \Setup \Console \Command \InstallCommand ;
12
13
13
14
/**
14
15
* The purpose of this class is enable/disable module and upgrade commands execution.
16
+ *
17
+ * @SuppressWarnings(PHPMD.TooManyPublicMethods)
15
18
*/
16
19
class CliCommand
17
20
{
18
21
/**
19
- * @var \Magento\Framework\ Shell
22
+ * @var Shell
20
23
*/
21
24
private $ shell ;
22
25
@@ -36,10 +39,7 @@ class CliCommand
36
39
private $ deploymentConfig ;
37
40
38
41
/**
39
- * ShellCommand constructor.
40
- *
41
- * @param TestModuleManager $testEnv
42
- * @param DeploymentConfig $deploymentConfig
42
+ * @param TestModuleManager $testEnv
43
43
* @internal param Shell $shell
44
44
*/
45
45
public function __construct (
@@ -53,8 +53,9 @@ public function __construct(
53
53
/**
54
54
* Copy Test module files and execute enable module command.
55
55
*
56
- * @param string $moduleName
56
+ * @param string $moduleName
57
57
* @return string
58
+ * @throws LocalizedException
58
59
*/
59
60
public function introduceModule ($ moduleName )
60
61
{
@@ -65,13 +66,14 @@ public function introduceModule($moduleName)
65
66
/**
66
67
* Execute enable module command.
67
68
*
68
- * @param string $moduleName
69
+ * @param string $moduleName
69
70
* @return string
71
+ * @throws LocalizedException
70
72
*/
71
73
public function enableModule ($ moduleName )
72
74
{
73
75
$ initParams = $ this ->parametersHolder ->getInitParams ();
74
- $ enableModuleCommand = ' php -f ' . BP . ' /bin/magento module:enable ' . $ moduleName
76
+ $ enableModuleCommand = $ this -> getCliScriptCommand () . ' module:enable ' . $ moduleName
75
77
. ' -n -vvv --magento-init-params=" ' . $ initParams ['magento-init-params ' ] . '" ' ;
76
78
return $ this ->shell ->execute ($ enableModuleCommand );
77
79
}
@@ -81,11 +83,12 @@ public function enableModule($moduleName)
81
83
*
82
84
* @param array $installParams
83
85
* @return string
86
+ * @throws LocalizedException
84
87
*/
85
88
public function upgrade ($ installParams = [])
86
89
{
87
90
$ 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=" '
89
92
. $ initParams ['magento-init-params ' ] . '" ' ;
90
93
$ installParams = $ this ->toCliArguments ($ installParams );
91
94
$ upgradeCommand .= ' ' . implode (" " , array_keys ($ installParams ));
@@ -96,13 +99,14 @@ public function upgrade($installParams = [])
96
99
/**
97
100
* Execute disable module command.
98
101
*
99
- * @param string $moduleName
102
+ * @param string $moduleName
100
103
* @return string
104
+ * @throws LocalizedException
101
105
*/
102
106
public function disableModule ($ moduleName )
103
107
{
104
108
$ initParams = $ this ->parametersHolder ->getInitParams ();
105
- $ disableModuleCommand = ' php -f ' . BP . ' /bin/magento module:disable ' . $ moduleName
109
+ $ disableModuleCommand = $ this -> getCliScriptCommand () . ' module:disable ' . $ moduleName
106
110
. ' -vvv --magento-init-params=" ' . $ initParams ['magento-init-params ' ] . '" ' ;
107
111
return $ this ->shell ->execute ($ disableModuleCommand );
108
112
}
@@ -111,14 +115,15 @@ public function disableModule($moduleName)
111
115
* Split quote db configuration.
112
116
*
113
117
* @return void
118
+ * @throws LocalizedException
114
119
*/
115
120
public function splitQuote ()
116
121
{
117
122
$ initParams = $ this ->parametersHolder ->getInitParams ();
118
123
$ installParams = $ this ->toCliArguments (
119
124
$ this ->parametersHolder ->getDbData ('checkout ' )
120
125
);
121
- $ command = ' php -f ' . BP . ' /bin/magento setup:db-schema:split-quote ' .
126
+ $ command = $ this -> getCliScriptCommand () . ' setup:db-schema:split-quote ' .
122
127
implode (" " , array_keys ($ installParams )) .
123
128
' -vvv --magento-init-params=" ' .
124
129
$ initParams ['magento-init-params ' ] . '" ' ;
@@ -130,14 +135,15 @@ public function splitQuote()
130
135
* Split sales db configuration.
131
136
*
132
137
* @return void
138
+ * @throws LocalizedException
133
139
*/
134
140
public function splitSales ()
135
141
{
136
142
$ initParams = $ this ->parametersHolder ->getInitParams ();
137
143
$ installParams = $ this ->toCliArguments (
138
144
$ this ->parametersHolder ->getDbData ('sales ' )
139
145
);
140
- $ command = ' php -f ' . BP . ' /bin/magento setup:db-schema:split-sales ' .
146
+ $ command = $ this -> getCliScriptCommand () . ' setup:db-schema:split-sales ' .
141
147
implode (" " , array_keys ($ installParams )) .
142
148
' -vvv --magento-init-params=" ' .
143
149
$ initParams ['magento-init-params ' ] . '" ' ;
@@ -151,7 +157,7 @@ public function splitSales()
151
157
public function cacheClean ()
152
158
{
153
159
$ initParams = $ this ->parametersHolder ->getInitParams ();
154
- $ command = ' php -f ' . BP . ' /bin/magento cache:clean ' .
160
+ $ command = $ this -> getCliScriptCommand () . ' cache:clean ' .
155
161
' -vvv --magento-init-params= ' .
156
162
$ initParams ['magento-init-params ' ];
157
163
@@ -162,11 +168,12 @@ public function cacheClean()
162
168
* Uninstall module
163
169
*
164
170
* @param string $moduleName
171
+ * @throws LocalizedException
165
172
*/
166
173
public function uninstallModule ($ moduleName )
167
174
{
168
175
$ 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 ' .
170
177
' -vvv --non-composer --magento-init-params=" ' .
171
178
$ initParams ['magento-init-params ' ] . '" ' ;
172
179
@@ -240,4 +247,29 @@ public function afterInstall()
240
247
->get (DeploymentConfig::class);
241
248
$ this ->deploymentConfig ->resetData ();
242
249
}
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
+ }
243
275
}
0 commit comments