7
7
8
8
namespace Magento \FunctionalTestingFramework \Console ;
9
9
10
- use Magento \FunctionalTestingFramework \Suite \Handlers \SuiteObjectHandler ;
11
10
use Magento \FunctionalTestingFramework \Config \MftfApplicationConfig ;
12
- use Magento \FunctionalTestingFramework \Test \Handlers \TestObjectHandler ;
13
11
use Symfony \Component \Console \Input \ArrayInput ;
14
- use Symfony \Component \Console \Input \InputArgument ;
15
12
use Symfony \Component \Console \Input \InputInterface ;
16
- use Symfony \Component \Console \Input \InputOption ;
17
13
use Symfony \Component \Console \Output \OutputInterface ;
18
14
use Symfony \Component \Process \Process ;
19
15
use Magento \FunctionalTestingFramework \Exceptions \TestFrameworkException ;
20
16
21
17
class RunTestFailedCommand extends BaseGenerateCommand
22
18
{
19
+ /**
20
+ * Default Test group to signify not in suite
21
+ */
23
22
const DEFAULT_TEST_GROUP = 'default ' ;
24
23
24
+ const TESTS_OUTPUT_DIR = TESTS_BP .
25
+ DIRECTORY_SEPARATOR .
26
+ "tests " .
27
+ DIRECTORY_SEPARATOR .
28
+ "_output " .
29
+ DIRECTORY_SEPARATOR ;
30
+
31
+ const TESTS_FAILED_FILE = self ::TESTS_OUTPUT_DIR . "failed " ;
32
+ const TESTS_RERUN_FILE = self ::TESTS_OUTPUT_DIR . "rerun_tests " ;
33
+
25
34
/**
26
35
* Configures the current command.
27
36
*
@@ -30,18 +39,7 @@ class RunTestFailedCommand extends BaseGenerateCommand
30
39
protected function configure ()
31
40
{
32
41
$ this ->setName ('run:failed ' )
33
- ->setDescription ('Execute a set of tests referenced via group annotations ' )
34
- ->addOption (
35
- 'skip-generate ' ,
36
- 'k ' ,
37
- InputOption::VALUE_NONE ,
38
- "only execute a group of tests without generating from source xml "
39
- )->addOption (
40
- "force " ,
41
- 'f ' ,
42
- InputOption::VALUE_NONE ,
43
- 'force generation of tests regardless of Magento Instance Configuration '
44
- );
42
+ ->setDescription ('Execute a set of tests referenced via failed file ' );
45
43
46
44
parent ::configure ();
47
45
}
@@ -55,41 +53,29 @@ protected function configure()
55
53
* @throws \Exception
56
54
*
57
55
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
56
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
58
57
*/
59
58
protected function execute (InputInterface $ input , OutputInterface $ output )
60
59
{
61
- $ skipGeneration = $ input ->getOption ('skip-generate ' );
62
- $ force = $ input ->getOption ('force ' );
63
- // $groups = $input->getArgument('groups');
64
- $ remove = $ input ->getOption ('remove ' );
65
-
66
- if ($ skipGeneration and $ remove ) {
67
- // "skip-generate" and "remove" options cannot be used at the same time
68
- throw new TestFrameworkException (
69
- "\"skip-generate \" and \"remove \" options can not be used at the same time. "
70
- );
71
- }
72
-
73
60
// Create Mftf Configuration
74
61
MftfApplicationConfig::create (
75
- $ force ,
62
+ false ,
76
63
MftfApplicationConfig::GENERATION_PHASE ,
77
64
false ,
78
65
false
79
66
);
80
67
81
- if (!$ skipGeneration ) {
82
- $ testConfiguration = $ this ->getFailedTestList ();
83
- $ command = $ this ->getApplication ()->find ('generate:tests ' );
84
- $ args = [
85
- '--tests ' => $ testConfiguration ,
86
- '--force ' => $ force ,
87
- '--remove ' => $ remove
88
- ];
68
+ $ testConfiguration = $ this ->getFailedTestList ();
89
69
90
- $ command ->run (new ArrayInput ($ args ), $ output );
70
+ if ($ testConfiguration === null ) {
71
+ return null ;
91
72
}
92
73
74
+ $ command = $ this ->getApplication ()->find ('generate:tests ' );
75
+ $ args = ['--tests ' => $ testConfiguration , '--remove ' => true ];
76
+
77
+ $ command ->run (new ArrayInput ($ args ), $ output );
78
+
93
79
$ codeceptionCommand = realpath (PROJECT_ROOT . '/vendor/bin/codecept ' ) . ' run functional --verbose --steps ' ;
94
80
95
81
$ process = new Process ($ codeceptionCommand );
@@ -106,7 +92,7 @@ function ($type, $buffer) use ($output) {
106
92
/**
107
93
* Returns a json string of tests that failed on the last run
108
94
*
109
- * @return string[]
95
+ * @return string
110
96
*/
111
97
private function getFailedTestList ()
112
98
{
@@ -121,10 +107,10 @@ private function getFailedTestList()
121
107
$ failedTestDetails = ['tests ' => [], 'suites ' => []];
122
108
123
109
if (realpath ($ failedTestPath )) {
124
-
125
- $ testList = file ($ failedTestPath ,FILE_IGNORE_NEW_LINES );
110
+ $ testList = $ this ->readFailedTestFile ($ failedTestPath );
126
111
127
112
foreach ($ testList as $ test ) {
113
+ $ this ->writeFailedTestToFile ($ test );
128
114
$ testInfo = explode (DIRECTORY_SEPARATOR , $ test );
129
115
$ testName = explode (": " , $ testInfo [count ($ testInfo ) - 1 ])[1 ];
130
116
$ suiteName = $ testInfo [count ($ testInfo ) - 2 ];
@@ -139,7 +125,44 @@ private function getFailedTestList()
139
125
}
140
126
}
141
127
}
128
+ if (empty ($ failedTestDetails ['tests ' ]) & empty ($ failedTestDetails ['suites ' ])) {
129
+ return null ;
130
+ }
131
+ if (empty ($ failedTestDetails ['tests ' ])) {
132
+ $ failedTestDetails ['tests ' ] = null ;
133
+ }
134
+ if (empty ($ failedTestDetails ['suites ' ])) {
135
+ $ failedTestDetails ['suites ' ] = null ;
136
+ }
142
137
$ testConfigurationJson = json_encode ($ failedTestDetails );
143
138
return $ testConfigurationJson ;
144
139
}
140
+
141
+ /**
142
+ * Returns an array of tests read from the failed test file in _output
143
+ *
144
+ * @param string $filePath
145
+ * @return array|boolean
146
+ */
147
+ private function readFailedTestFile ($ filePath )
148
+ {
149
+ return file ($ filePath , FILE_IGNORE_NEW_LINES );
150
+ }
151
+
152
+ /**
153
+ * Writes the test name to a file if it does not already exist
154
+ *
155
+ * @param string $test
156
+ * @return void
157
+ */
158
+ private function writeFailedTestToFile ($ test )
159
+ {
160
+ if (realpath (self ::TESTS_RERUN_FILE )) {
161
+ if (strpos (file_get_contents (self ::TESTS_RERUN_FILE ), $ test ) == false ) {
162
+ file_put_contents (self ::TESTS_RERUN_FILE , $ test . "\n" , FILE_APPEND );
163
+ }
164
+ } else {
165
+ file_put_contents (self ::TESTS_RERUN_FILE , $ test . "\n" );
166
+ }
167
+ }
145
168
}
0 commit comments