1616use Symfony \Component \Console \Input \InputInterface ;
1717use Symfony \Component \Console \Output \OutputInterface ;
1818use Magento \FunctionalTestingFramework \Util \ModuleResolver ;
19+ use Magento \FunctionalTestingFramework \Module \MagentoWebDriver ;
20+ use Magento \FunctionalTestingFramework \Module \MagentoWebDriverDoctor ;
1921
20- class TroubleShootCommand extends Command
22+ class DoctorCommand extends Command
2123{
2224 const CODECEPTION_AUTOLOAD_FILE = PROJECT_ROOT . '/vendor/codeception/codeception/autoload.php ' ;
2325 const MFTF_CODECEPTION_CONFIG_FILE = ENV_FILE_PATH . 'codeception.yml ' ;
2426 const SUITE = 'functional ' ;
25- const REQUIRED_PHP_EXTS = ['CURL ' , 'mbstring ' , 'bcmath ' , 'zip ' , 'dom ' , 'gd ' , 'intl ' ];
2627
2728 /**
2829 * Command Output
@@ -31,14 +32,21 @@ class TroubleShootCommand extends Command
3132 */
3233 private $ output ;
3334
35+ /**
36+ * Exception Context
37+ *
38+ * @var array
39+ */
40+ private $ context = [];
41+
3442 /**
3543 * Configures the current command.
3644 *
3745 * @return void
3846 */
3947 protected function configure ()
4048 {
41- $ this ->setName ('troubleshoot ' )
49+ $ this ->setName ('doctor ' )
4250 ->setDescription (
4351 'This command checks environment readiness for generating and running MFTF tests. '
4452 );
@@ -62,24 +70,22 @@ protected function execute(InputInterface $input, OutputInterface $output)
6270 $ this ->output = $ output ;
6371 MftfApplicationConfig::create (
6472 false ,
65- MftfApplicationConfig::DIAGNOSTIC_PHASE ,
73+ MftfApplicationConfig::GENERATION_PHASE ,
6674 $ verbose ,
6775 MftfApplicationConfig::LEVEL_DEVELOPER ,
6876 false
6977 );
7078
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-
7779 // Check authentication to Magento Admin
7880 $ status = $ this ->checkAuthenticationToMagentoAdmin ();
7981 $ cmdStatus = $ cmdStatus && !$ status ? false : $ cmdStatus ;
8082
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 ();
8389 $ cmdStatus = $ cmdStatus && !$ status ? false : $ cmdStatus ;
8490
8591 if ($ cmdStatus ) {
@@ -90,70 +96,104 @@ protected function execute(InputInterface $input, OutputInterface $output)
9096 }
9197
9298 /**
93- * Check php extention is installed and available
99+ * Check authentication to Magento Admin
94100 *
95- * @param string $ext
96101 * @return boolean
97102 */
98- private function checkPhpExtIsAvailable ( $ ext )
103+ private function checkAuthenticationToMagentoAdmin ( )
99104 {
100105 $ 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 ();
103109 $ this ->output ->writeln ('Successful ' );
104110 $ 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 ());
110113 }
111114 return $ result ;
112115 }
113116
114117 /**
115- * Check authentication to Magento Admin
118+ * Check Connection to Selenium Server
116119 *
117120 * @return boolean
118121 */
119- private function checkAuthenticationToMagentoAdmin ()
122+ private function checkConnectionToSeleniumServer ()
120123 {
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 {
125132 $ this ->output ->writeln ('Successful ' );
126- $ result = true ;
127- } catch (TestFrameworkException $ e ) {
128- $ this ->output ->writeln ($ e ->getMessage ());
133+ return true ;
129134 }
130- return $ result ;
131135 }
132136
133137 /**
134- * Check Connectivity to Selenium Server
138+ * Check access to Magento CLI setup
135139 *
136140 * @return boolean
137141 */
138- private function checkConnectivityToSeleniumServer ()
142+ private function checkAccessToMagentoCLI ()
139143 {
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;
141170
142- // Check connectivity to Selenium through Codeception
143- $ this ->output ->writeln ("\nChecking connectivity to Selenium Server ... " );
144171 require_once realpath (self ::CODECEPTION_AUTOLOAD_FILE );
145172
146173 $ config = Configuration::config (realpath (self ::MFTF_CODECEPTION_CONFIG_FILE ));
147174 $ 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+
148190 $ dispatcher = new EventDispatcher ();
149191 $ suiteManager = new SuiteManager ($ dispatcher , self ::SUITE , $ settings );
150192 try {
151193 $ suiteManager ->initialize ();
152- $ this ->output ->writeln ('Successful ' );
153- $ result = true ;
194+ $ this ->context = ['Successful ' ];
154195 } catch (TestFrameworkException $ e ) {
155- $ this ->output -> writeln ( $ e ->getMessage () );
196+ $ this ->context = $ e ->getContext ( );
156197 }
157- return $ result ;
158198 }
159199}
0 commit comments