@@ -63,28 +63,35 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6363 );
6464 }
6565
66+ $ testConfiguration = $ this ->getTestAndSuiteConfiguration ($ tests );
67+
6668 if (!$ skipGeneration ) {
6769 $ command = $ this ->getApplication ()->find ('generate:tests ' );
6870 $ args = [
69- '--tests ' => json_encode ([
70- 'tests ' => $ tests ,
71- 'suites ' => null
72- ]),
71+ '--tests ' => $ testConfiguration ,
7372 '--force ' => $ force ,
7473 '--remove ' => $ remove ,
7574 '--debug ' => $ debug ,
7675 '--allowSkipped ' => $ allowSkipped
7776 ];
7877 $ command ->run (new ArrayInput ($ args ), $ output );
7978 }
79+ // tests with resolved suite references
80+ $ resolvedTests = $ this ->resolveSuiteReferences ($ testConfiguration );
8081
81- $ returnCode = 0 ;
8282 $ codeceptionCommand = realpath (PROJECT_ROOT . '/vendor/bin/codecept ' ) . ' run functional ' ;
8383 $ testsDirectory = TESTS_MODULE_PATH . DIRECTORY_SEPARATOR . TestGenerator::GENERATED_DIR . DIRECTORY_SEPARATOR ;
84+ $ returnCode = 0 ;
8485 //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 ' ;
86+ foreach ($ resolvedTests as $ test ) {
87+ //set directory as suite name for tests in suite, if not set to "default"
88+ if (strpos ($ test , ': ' )) {
89+ list ($ testGroup , $ testName ) = explode (": " , $ test );
90+ } else {
91+ list ($ testGroup , $ testName ) = [TestGenerator::DEFAULT_DIR , $ test ];
92+ }
93+ $ testGroup = $ testGroup . DIRECTORY_SEPARATOR ;
94+ $ testName = $ 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+ /**
116+ * Get an array of tests with resolved suite references from $testConfiguration
117+ * eg: if test is referenced in a suite, it'll be stored in format suite:test
118+ * @param string $testConfigurationJson
119+ * @return array
120+ */
121+ private function resolveSuiteReferences ($ testConfigurationJson )
122+ {
123+ $ testConfiguration = json_decode ($ testConfigurationJson , true );
124+ $ testsArray = $ testConfiguration ['tests ' ] ?? [];
125+ $ suitesArray = $ testConfiguration ['suites ' ] ?? [];
126+ $ testArrayBuilder = [];
127+
128+ foreach ($ suitesArray as $ suite => $ tests ) {
129+ foreach ($ tests as $ test ) {
130+ $ testArrayBuilder [] = "$ suite: $ test " ;
131+ }
132+ }
133+ return array_merge ($ testArrayBuilder , $ testsArray );
134+ }
107135}
0 commit comments