16
16
use Symfony \Component \Console \Input \InputInterface ;
17
17
use Symfony \Component \Console \Output \OutputInterface ;
18
18
use Magento \FunctionalTestingFramework \Util \ModuleResolver ;
19
+ use Magento \FunctionalTestingFramework \Module \MagentoWebDriver ;
20
+ use Magento \FunctionalTestingFramework \Module \MagentoWebDriverDoctor ;
19
21
20
- class TroubleShootCommand extends Command
22
+ class DoctorCommand extends Command
21
23
{
22
24
const CODECEPTION_AUTOLOAD_FILE = PROJECT_ROOT . '/vendor/codeception/codeception/autoload.php ' ;
23
25
const MFTF_CODECEPTION_CONFIG_FILE = ENV_FILE_PATH . 'codeception.yml ' ;
24
26
const SUITE = 'functional ' ;
25
- const REQUIRED_PHP_EXTS = ['CURL ' , 'mbstring ' , 'bcmath ' , 'zip ' , 'dom ' , 'gd ' , 'intl ' ];
26
27
27
28
/**
28
29
* Command Output
@@ -31,14 +32,21 @@ class TroubleShootCommand extends Command
31
32
*/
32
33
private $ output ;
33
34
35
+ /**
36
+ * Exception Context
37
+ *
38
+ * @var array
39
+ */
40
+ private $ context = [];
41
+
34
42
/**
35
43
* Configures the current command.
36
44
*
37
45
* @return void
38
46
*/
39
47
protected function configure ()
40
48
{
41
- $ this ->setName ('troubleshoot ' )
49
+ $ this ->setName ('doctor ' )
42
50
->setDescription (
43
51
'This command checks environment readiness for generating and running MFTF tests. '
44
52
);
@@ -62,24 +70,22 @@ protected function execute(InputInterface $input, OutputInterface $output)
62
70
$ this ->output = $ output ;
63
71
MftfApplicationConfig::create (
64
72
false ,
65
- MftfApplicationConfig::DIAGNOSTIC_PHASE ,
73
+ MftfApplicationConfig::GENERATION_PHASE ,
66
74
$ verbose ,
67
75
MftfApplicationConfig::LEVEL_DEVELOPER ,
68
76
false
69
77
);
70
78
71
- // Check required PHP extensions
72
- foreach (self ::REQUIRED_PHP_EXTS as $ ext ) {
73
- $ status = $ this ->checkPhpExtIsAvailable ($ ext );
74
- $ cmdStatus = $ cmdStatus && !$ status ? false : $ cmdStatus ;
75
- }
76
-
77
79
// Check authentication to Magento Admin
78
80
$ status = $ this ->checkAuthenticationToMagentoAdmin ();
79
81
$ cmdStatus = $ cmdStatus && !$ status ? false : $ cmdStatus ;
80
82
81
- // Check connectivity and authentication to Magento Admin
82
- $ status = $ this ->checkConnectivityToSeleniumServer ();
83
+ // Check connection to Selenium
84
+ $ status = $ this ->checkConnectionToSeleniumServer ();
85
+ $ cmdStatus = $ cmdStatus && !$ status ? false : $ cmdStatus ;
86
+
87
+ // Check access to Magento CLI
88
+ $ status = $ this ->checkAccessToMagentoCLI ();
83
89
$ cmdStatus = $ cmdStatus && !$ status ? false : $ cmdStatus ;
84
90
85
91
if ($ cmdStatus ) {
@@ -90,70 +96,104 @@ protected function execute(InputInterface $input, OutputInterface $output)
90
96
}
91
97
92
98
/**
93
- * Check php extention is installed and available
99
+ * Check authentication to Magento Admin
94
100
*
95
- * @param string $ext
96
101
* @return boolean
97
102
*/
98
- private function checkPhpExtIsAvailable ( $ ext )
103
+ private function checkAuthenticationToMagentoAdmin ( )
99
104
{
100
105
$ result = false ;
101
- $ this ->output ->writeln ("\nChecking PHP extenstion \"{$ ext }\" ... " );
102
- if (extension_loaded (strtolower ($ ext ))) {
106
+ try {
107
+ $ this ->output ->writeln ("\nChecking authentication to Magento Admin ... " );
108
+ ModuleResolver::getInstance ()->getAdminToken ();
103
109
$ this ->output ->writeln ('Successful ' );
104
110
$ result = true ;
105
- } else {
106
- $ this ->output ->writeln (
107
- "MFTF requires \"{$ ext }\" extension installed to make tests run \n"
108
- . "Please make sure that the PHP you run has \"{$ ext }\" installed and enabled. "
109
- );
111
+ } catch (TestFrameworkException $ e ) {
112
+ $ this ->output ->writeln ($ e ->getMessage ());
110
113
}
111
114
return $ result ;
112
115
}
113
116
114
117
/**
115
- * Check authentication to Magento Admin
118
+ * Check Connection to Selenium Server
116
119
*
117
120
* @return boolean
118
121
*/
119
- private function checkAuthenticationToMagentoAdmin ()
122
+ private function checkConnectionToSeleniumServer ()
120
123
{
121
- $ result = false ;
122
- try {
123
- $ this ->output ->writeln ("\nChecking authentication to Magento Admin ... " );
124
- ModuleResolver::getInstance ()->getAdminToken ();
124
+ // Check connection to Selenium through Codeception
125
+ $ this ->output ->writeln ("\nChecking connection to Selenium Server ... " );
126
+ $ this ->runMagentoWebDriverDoctor ();
127
+
128
+ if (isset ($ this ->context [MagentoWebDriverDoctor::EXCEPTION_TYPE_SELENIUM ])) {
129
+ $ this ->output ->write ($ this ->context [MagentoWebDriverDoctor::EXCEPTION_TYPE_SELENIUM ] . "\n" );
130
+ return false ;
131
+ } else {
125
132
$ this ->output ->writeln ('Successful ' );
126
- $ result = true ;
127
- } catch (TestFrameworkException $ e ) {
128
- $ this ->output ->writeln ($ e ->getMessage ());
133
+ return true ;
129
134
}
130
- return $ result ;
131
135
}
132
136
133
137
/**
134
- * Check Connectivity to Selenium Server
138
+ * Check access to Magento CLI setup
135
139
*
136
140
* @return boolean
137
141
*/
138
- private function checkConnectivityToSeleniumServer ()
142
+ private function checkAccessToMagentoCLI ()
139
143
{
140
- $ result = false ;
144
+ // Check Magento CLI setup
145
+ $ this ->output ->writeln ("\nChecking access to Magento CLI ... " );
146
+ $ this ->runMagentoWebDriverDoctor ();
147
+
148
+ if (isset ($ this ->context [MagentoWebDriverDoctor::EXCEPTION_TYPE_MAGENTO_CLI ])) {
149
+ $ this ->output ->write ($ this ->context [MagentoWebDriverDoctor::EXCEPTION_TYPE_MAGENTO_CLI ] . "\n" );
150
+ return false ;
151
+ } else {
152
+ $ this ->output ->writeln ('Successful ' );
153
+ return true ;
154
+ }
155
+ }
156
+
157
+ /**
158
+ * Run diagnose through MagentoWebDriverDoctor
159
+ *
160
+ * @return void
161
+ */
162
+ private function runMagentoWebDriverDoctor ()
163
+ {
164
+ if (!empty ($ this ->context )) {
165
+ return ;
166
+ }
167
+
168
+ $ magentoWebDriver = '\\' . MagentoWebDriver::class;
169
+ $ magentoWebDriverDoctor = '\\' . MagentoWebDriverDoctor::class;
141
170
142
- // Check connectivity to Selenium through Codeception
143
- $ this ->output ->writeln ("\nChecking connectivity to Selenium Server ... " );
144
171
require_once realpath (self ::CODECEPTION_AUTOLOAD_FILE );
145
172
146
173
$ config = Configuration::config (realpath (self ::MFTF_CODECEPTION_CONFIG_FILE ));
147
174
$ settings = Configuration::suiteSettings (self ::SUITE , $ config );
175
+
176
+ // Enable MagentoWebDriverDoctor
177
+ $ settings ['modules ' ]['enabled ' ][] = $ magentoWebDriverDoctor ;
178
+ $ settings ['modules ' ]['config ' ][$ magentoWebDriverDoctor ] =
179
+ $ settings ['modules ' ]['config ' ][$ magentoWebDriver ];
180
+
181
+ // Disable MagentoWebDriver to avoid conflicts
182
+ foreach ($ settings ['modules ' ]['enabled ' ] as $ index => $ module ) {
183
+ if ($ module == $ magentoWebDriver ) {
184
+ unset($ settings ['modules ' ]['enabled ' ][$ index ]);
185
+ break ;
186
+ }
187
+ }
188
+ unset($ settings ['modules ' ]['config ' ][$ magentoWebDriver ]);
189
+
148
190
$ dispatcher = new EventDispatcher ();
149
191
$ suiteManager = new SuiteManager ($ dispatcher , self ::SUITE , $ settings );
150
192
try {
151
193
$ suiteManager ->initialize ();
152
- $ this ->output ->writeln ('Successful ' );
153
- $ result = true ;
194
+ $ this ->context = ['Successful ' ];
154
195
} catch (TestFrameworkException $ e ) {
155
- $ this ->output -> writeln ( $ e ->getMessage () );
196
+ $ this ->context = $ e ->getContext ( );
156
197
}
157
- return $ result ;
158
198
}
159
199
}
0 commit comments