18
18
use Magento \FunctionalTestingFramework \Util \ModuleResolver ;
19
19
use Magento \FunctionalTestingFramework \Module \MagentoWebDriver ;
20
20
use Magento \FunctionalTestingFramework \Module \MagentoWebDriverDoctor ;
21
+ use Symfony \Component \Console \Style \SymfonyStyle ;
21
22
22
23
class DoctorCommand extends Command
23
24
{
24
25
const CODECEPTION_AUTOLOAD_FILE = PROJECT_ROOT . '/vendor/codeception/codeception/autoload.php ' ;
25
26
const MFTF_CODECEPTION_CONFIG_FILE = ENV_FILE_PATH . 'codeception.yml ' ;
26
27
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 " ;
31
28
32
29
/**
33
- * Command Output
30
+ * Console output style
34
31
*
35
- * @var OutputInterface
32
+ * @var SymfonyStyle
36
33
*/
37
- private $ output ;
34
+ private $ ioStyle ;
38
35
39
36
/**
40
37
* Exception Context
@@ -63,17 +60,17 @@ protected function configure()
63
60
* @param OutputInterface $output
64
61
* @return integer
65
62
* @throws TestFrameworkException
66
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
67
63
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
68
64
*/
69
65
protected function execute (InputInterface $ input , OutputInterface $ output )
70
66
{
67
+ // For output style
68
+ $ this ->ioStyle = new SymfonyStyle ($ input , $ output );
69
+
71
70
$ cmdStatus = true ;
72
71
73
72
// Config application
74
73
$ verbose = $ output ->isVerbose ();
75
- $ this ->input = $ input ;
76
- $ this ->output = $ output ;
77
74
MftfApplicationConfig::create (
78
75
false ,
79
76
MftfApplicationConfig::GENERATION_PHASE ,
@@ -126,14 +123,15 @@ private function checkAuthenticationToMagentoAdmin()
126
123
{
127
124
$ result = false ;
128
125
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 ... " );
132
127
ModuleResolver::getInstance ()->getAdminToken ();
133
- $ this ->output -> writeln ( self :: COLOR_LIGHT_GREEN . 'Successful ' . self :: COLOR_RESTORE );
128
+ $ this ->ioStyle -> success ( 'Successful ' );
134
129
$ result = true ;
135
130
} 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
+ );
137
135
}
138
136
return $ result ;
139
137
}
@@ -148,14 +146,14 @@ private function checkAuthenticationToMagentoAdmin()
148
146
*/
149
147
private function checkContextOnStep ($ exceptionType , $ message )
150
148
{
151
- $ this ->output -> writeln ( "\n" . self :: COLOR_LIGHT_DEFAULT . $ message . self :: COLOR_RESTORE );
149
+ $ this ->ioStyle -> text ( $ message . ' ... ' );
152
150
$ this ->runMagentoWebDriverDoctor ();
153
151
154
152
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 ]);
156
154
return false ;
157
155
} else {
158
- $ this ->output -> writeln ( self :: COLOR_LIGHT_GREEN . 'Successful ' . self :: COLOR_RESTORE );
156
+ $ this ->ioStyle -> success ( 'Successful ' );
159
157
return true ;
160
158
}
161
159
}
0 commit comments