@@ -64,27 +64,34 @@ protected function execute(InputInterface $input, OutputInterface $output): int
64
64
}
65
65
66
66
if (!$ skipGeneration ) {
67
+ $ testConfiguration = $ this ->getTestAndSuiteConfiguration ($ tests );
67
68
$ command = $ this ->getApplication ()->find ('generate:tests ' );
68
69
$ args = [
69
- '--tests ' => json_encode ([
70
- 'tests ' => $ tests ,
71
- 'suites ' => null
72
- ]),
70
+ '--tests ' => json_encode ($ testConfiguration ),
73
71
'--force ' => $ force ,
74
72
'--remove ' => $ remove ,
75
73
'--debug ' => $ debug ,
76
74
'--allowSkipped ' => $ allowSkipped
77
75
];
78
76
$ command ->run (new ArrayInput ($ args ), $ output );
79
77
}
80
-
78
+ // tests with resolved suite references
79
+ $ resolvedTests = $ this ->getResolvedTests ($ testConfiguration );
81
80
$ returnCode = 0 ;
82
81
$ codeceptionCommand = realpath (PROJECT_ROOT . '/vendor/bin/codecept ' ) . ' run functional ' ;
83
82
$ testsDirectory = TESTS_MODULE_PATH . DIRECTORY_SEPARATOR . TestGenerator::GENERATED_DIR . DIRECTORY_SEPARATOR ;
84
83
//execute only tests specified as arguments in run command
85
- foreach ($ tests as $ test ) {
86
- $ testGroup = TestGenerator::DEFAULT_DIR . DIRECTORY_SEPARATOR ;
87
- $ testName = $ test . 'Cest.php ' ;
84
+ foreach ($ resolvedTests as $ test ){
85
+ // for tests in suite, set directory as suite name
86
+ if (strpos ($ test , ': ' )) {
87
+ list ($ suite , $ testName ) = explode (": " , $ test );
88
+ }
89
+ // for standalone tests set directory as "default"
90
+ else {
91
+ list ($ suite , $ testName ) = [TestGenerator::DEFAULT_DIR , $ test ];
92
+ }
93
+ $ testGroup = $ suite . DIRECTORY_SEPARATOR ;
94
+ $ testName .= 'Cest.php ' ;
88
95
if (!realpath ($ testsDirectory . $ testGroup . $ testName )) {
89
96
throw new TestFrameworkException (
90
97
$ testName . " is not available under " . $ testsDirectory . $ testGroup
@@ -104,4 +111,25 @@ function ($type, $buffer) use ($output) {
104
111
}
105
112
return $ returnCode ;
106
113
}
114
+
115
+ /** Get an array of tests with resolved suite references from $testConfiguration
116
+ * eg: if test is referenced in a suite, it'll be stored in format "SuiteName:Testname";
117
+ * if not it'll be stored as is.
118
+ * @param $testConfiguration
119
+ * @return array
120
+ */
121
+ private function getResolvedTests ($ testConfiguration )
122
+ {
123
+ $ testsArray = $ testConfiguration ['tests ' ] ?? [];
124
+ $ suitesArray = $ testConfiguration ['suites ' ] ?? [];
125
+ $ testArrayBuilder = [];
126
+ foreach ($ suitesArray as $ suite => $ tests ) {
127
+ $ testArrayBuilder = array_merge ($ testArrayBuilder ,
128
+ array_map (function ($ test ) use ($ suite )
129
+ { return $ suite . ': ' . $ test ; }, $ tests ));
130
+ }
131
+ return array_merge ($ testArrayBuilder , $ testsArray );
132
+
133
+
134
+ }
107
135
}
0 commit comments