@@ -36,6 +36,7 @@ class BaseGenerateCommand extends Command
36
36
const CODECEPT_RUN = 'codecept:run ' ;
37
37
const CODECEPT_RUN_FUNCTIONAL = self ::CODECEPT_RUN . ' functional ' ;
38
38
const CODECEPT_RUN_OPTION_NO_EXIT = ' --no-exit ' ;
39
+ const FAILED_FILE = 'failed ' ;
39
40
40
41
/**
41
42
* Enable pause()
@@ -44,13 +45,34 @@ class BaseGenerateCommand extends Command
44
45
*/
45
46
private $ enablePause = null ;
46
47
48
+ /**
49
+ * Full path to '_output' dir
50
+ *
51
+ * @var string
52
+ */
53
+ private $ testsOutputDir = null ;
54
+
55
+ /**
56
+ * String contains all 'failed' tests
57
+ *
58
+ * @var string
59
+ */
60
+ private $ allFailed ;
61
+
47
62
/**
48
63
* Console output style
49
64
*
50
65
* @var SymfonyStyle
51
66
*/
52
67
protected $ ioStyle = null ;
53
68
69
+ /**
70
+ * Full path to 'failed' file
71
+ *
72
+ * @var string
73
+ */
74
+ protected $ testsFailedFile = null ;
75
+
54
76
/**
55
77
* Configures the base command.
56
78
*
@@ -270,4 +292,76 @@ protected function codeceptRunTest(string $commandStr, OutputInterface $output)
270
292
$ command = $ this ->getApplication ()->find (self ::CODECEPT_RUN );
271
293
return $ command ->run ($ input , $ output );
272
294
}
295
+
296
+ /**
297
+ * Return tests _output directory
298
+ *
299
+ * @return string
300
+ * @throws TestFrameworkException
301
+ */
302
+ protected function getTestsOutputDir ()
303
+ {
304
+ if (!$ this ->testsOutputDir ) {
305
+ $ this ->testsOutputDir = FilePathFormatter::format (TESTS_BP ) .
306
+ "tests " .
307
+ DIRECTORY_SEPARATOR .
308
+ "_output " .
309
+ DIRECTORY_SEPARATOR ;
310
+ }
311
+
312
+ return $ this ->testsOutputDir ;
313
+ }
314
+
315
+ /**
316
+ * Save 'failed' tests
317
+ *
318
+ * @return void
319
+ */
320
+ protected function appendRunFailed ()
321
+ {
322
+ try {
323
+ if (!$ this ->testsFailedFile ) {
324
+ $ this ->testsFailedFile = $ this ->getTestsOutputDir () . self ::FAILED_FILE ;
325
+ }
326
+
327
+ if (file_exists ($ this ->testsFailedFile )) {
328
+ // Save 'failed' tests
329
+ $ contents = file_get_contents ($ this ->testsFailedFile );
330
+ if ($ contents !== false && !empty ($ contents )) {
331
+ $ this ->allFailed .= trim ($ contents ) . PHP_EOL ;
332
+ }
333
+ }
334
+ } catch (TestFrameworkException $ e ) {
335
+ }
336
+ }
337
+
338
+ /**
339
+ * Apply 'allFailed' in 'failed' file
340
+ *
341
+ * @return void
342
+ * @SuppressWarnings(PHPMD.CyclomaticComplexity)
343
+ */
344
+ protected function applyAllFailed ()
345
+ {
346
+ try {
347
+ if (!$ this ->testsFailedFile ) {
348
+ $ this ->testsFailedFile = $ this ->getTestsOutputDir () . self ::FAILED_FILE ;
349
+ }
350
+
351
+ if (!empty ($ this ->allFailed )) {
352
+ // Update 'failed' with content from 'allFailed'
353
+ if (file_exists ($ this ->testsFailedFile )) {
354
+ rename ($ this ->testsFailedFile , $ this ->testsFailedFile . '.copy ' );
355
+ }
356
+ if (file_put_contents ($ this ->testsFailedFile , $ this ->allFailed ) === false
357
+ && file_exists ($ this ->testsFailedFile . '.copy ' )) {
358
+ rename ($ this ->testsFailedFile . '.copy ' , $ this ->testsFailedFile );
359
+ }
360
+ if (file_exists ($ this ->testsFailedFile . '.copy ' )) {
361
+ unlink ($ this ->testsFailedFile . '.copy ' );
362
+ }
363
+ }
364
+ } catch (TestFrameworkException $ e ) {
365
+ }
366
+ }
273
367
}
0 commit comments