1818use Magento \FunctionalTestingFramework \Util \ModuleResolver ;
1919use Magento \FunctionalTestingFramework \Module \MagentoWebDriver ;
2020use Magento \FunctionalTestingFramework \Module \MagentoWebDriverDoctor ;
21+ use Symfony \Component \Console \Style \SymfonyStyle ;
2122
2223class DoctorCommand extends Command
2324{
2425 const CODECEPTION_AUTOLOAD_FILE = PROJECT_ROOT . '/vendor/codeception/codeception/autoload.php ' ;
2526 const MFTF_CODECEPTION_CONFIG_FILE = ENV_FILE_PATH . 'codeception.yml ' ;
2627 const SUITE = 'functional ' ;
27- const COLOR_LIGHT_GREEN = "\e[1;32m " ;
28- const COLOR_LIGHT_RED = "\e[1;31m " ;
29- const COLOR_LIGHT_DEFAULT = "\e[1;39m " ;
30- const COLOR_RESTORE = "\e[0m " ;
3128
3229 /**
33- * Command Output
30+ * Console output style
3431 *
35- * @var OutputInterface
32+ * @var SymfonyStyle
3633 */
37- private $ output ;
34+ private $ ioStyle ;
3835
3936 /**
4037 * Exception Context
@@ -63,17 +60,17 @@ protected function configure()
6360 * @param OutputInterface $output
6461 * @return integer
6562 * @throws TestFrameworkException
66- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
6763 * @SuppressWarnings(PHPMD.CyclomaticComplexity)
6864 */
6965 protected function execute (InputInterface $ input , OutputInterface $ output )
7066 {
67+ // For output style
68+ $ this ->ioStyle = new SymfonyStyle ($ input , $ output );
69+
7170 $ cmdStatus = true ;
7271
7372 // Config application
7473 $ verbose = $ output ->isVerbose ();
75- $ this ->input = $ input ;
76- $ this ->output = $ output ;
7774 MftfApplicationConfig::create (
7875 false ,
7976 MftfApplicationConfig::GENERATION_PHASE ,
@@ -126,14 +123,15 @@ private function checkAuthenticationToMagentoAdmin()
126123 {
127124 $ result = false ;
128125 try {
129- $ this ->output ->writeln (
130- "\n" . self ::COLOR_LIGHT_DEFAULT . "Authenticating admin account by API ... " . self ::COLOR_RESTORE
131- );
126+ $ this ->ioStyle ->text ("Requesting API token for admin user through cURL ... " );
132127 ModuleResolver::getInstance ()->getAdminToken ();
133- $ this ->output -> writeln ( self :: COLOR_LIGHT_GREEN . 'Successful ' . self :: COLOR_RESTORE );
128+ $ this ->ioStyle -> success ( 'Successful ' );
134129 $ result = true ;
135130 } catch (TestFrameworkException $ e ) {
136- $ this ->output ->writeln (self ::COLOR_LIGHT_RED . $ e ->getMessage () . self ::COLOR_RESTORE );
131+ $ this ->ioStyle ->error (
132+ $ e ->getMessage ()
133+ . "\nPlease verify MAGENTO_ADMIN_USERNAME and MAGENTO_ADMIN_PASSWORD in .env. "
134+ );
137135 }
138136 return $ result ;
139137 }
@@ -148,14 +146,14 @@ private function checkAuthenticationToMagentoAdmin()
148146 */
149147 private function checkContextOnStep ($ exceptionType , $ message )
150148 {
151- $ this ->output -> writeln ( "\n" . self :: COLOR_LIGHT_DEFAULT . $ message . self :: COLOR_RESTORE );
149+ $ this ->ioStyle -> text ( $ message . ' ... ' );
152150 $ this ->runMagentoWebDriverDoctor ();
153151
154152 if (isset ($ this ->context [$ exceptionType ])) {
155- $ this ->output -> writeln ( self :: COLOR_LIGHT_RED . $ this ->context [$ exceptionType ] . self :: COLOR_RESTORE );
153+ $ this ->ioStyle -> error ( $ this ->context [$ exceptionType ]);
156154 return false ;
157155 } else {
158- $ this ->output -> writeln ( self :: COLOR_LIGHT_GREEN . 'Successful ' . self :: COLOR_RESTORE );
156+ $ this ->ioStyle -> success ( 'Successful ' );
159157 return true ;
160158 }
161159 }
0 commit comments