@@ -63,28 +63,35 @@ protected function execute(InputInterface $input, OutputInterface $output): int
63
63
);
64
64
}
65
65
66
+ $ testConfiguration = $ this ->getTestAndSuiteConfiguration ($ tests );
67
+
66
68
if (!$ skipGeneration ) {
67
69
$ command = $ this ->getApplication ()->find ('generate:tests ' );
68
70
$ args = [
69
- '--tests ' => json_encode ([
70
- 'tests ' => $ tests ,
71
- 'suites ' => null
72
- ]),
71
+ '--tests ' => $ testConfiguration ,
73
72
'--force ' => $ force ,
74
73
'--remove ' => $ remove ,
75
74
'--debug ' => $ debug ,
76
75
'--allowSkipped ' => $ allowSkipped
77
76
];
78
77
$ command ->run (new ArrayInput ($ args ), $ output );
79
78
}
79
+ // tests with resolved suite references
80
+ $ resolvedTests = $ this ->resolveSuiteReferences ($ testConfiguration );
80
81
81
- $ returnCode = 0 ;
82
82
$ codeceptionCommand = realpath (PROJECT_ROOT . '/vendor/bin/codecept ' ) . ' run functional ' ;
83
83
$ testsDirectory = TESTS_MODULE_PATH . DIRECTORY_SEPARATOR . TestGenerator::GENERATED_DIR . DIRECTORY_SEPARATOR ;
84
+ $ returnCode = 0 ;
84
85
//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 ' ;
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
+ /**
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
+ }
107
135
}
0 commit comments