@@ -64,27 +64,34 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6464 }
6565
6666 if (!$ skipGeneration ) {
67+ $ testConfiguration = $ this ->getTestAndSuiteConfiguration ($ tests );
6768 $ command = $ this ->getApplication ()->find ('generate:tests ' );
6869 $ args = [
69- '--tests ' => json_encode ([
70- 'tests ' => $ tests ,
71- 'suites ' => null
72- ]),
70+ '--tests ' => json_encode ($ testConfiguration ),
7371 '--force ' => $ force ,
7472 '--remove ' => $ remove ,
7573 '--debug ' => $ debug ,
7674 '--allowSkipped ' => $ allowSkipped
7775 ];
7876 $ command ->run (new ArrayInput ($ args ), $ output );
7977 }
80-
78+ // tests with resolved suite references
79+ $ resolvedTests = $ this ->getResolvedTests ($ testConfiguration );
8180 $ returnCode = 0 ;
8281 $ codeceptionCommand = realpath (PROJECT_ROOT . '/vendor/bin/codecept ' ) . ' run functional ' ;
8382 $ testsDirectory = TESTS_MODULE_PATH . DIRECTORY_SEPARATOR . TestGenerator::GENERATED_DIR . DIRECTORY_SEPARATOR ;
8483 //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 ' ;
8895 if (!realpath ($ testsDirectory . $ testGroup . $ testName )) {
8996 throw new TestFrameworkException (
9097 $ testName . " is not available under " . $ testsDirectory . $ testGroup
@@ -104,4 +111,25 @@ function ($type, $buffer) use ($output) {
104111 }
105112 return $ returnCode ;
106113 }
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+ }
107135}
0 commit comments