Skip to content

Commit 459c30f

Browse files
committed
fixed a problem with nested testsuites
* the reporter now selects every `testsuites` that has `testcases` and ignores all `testsuites` with only `sub-testsuites` * it iterates through all errors and adds them only to the resultset if the set is not empty -> that is necessary because there are still testsuites that includes `testcases` and `testsuites`
1 parent eb12bb3 commit 459c30f

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

functions.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,8 @@ function process_junit_xml( $xml_string )
105105

106106
$results['testsuites'] = array();
107107

108-
$testsuites = $xml->xpath( '//testsuites//testsuite[ ( @file ) and ( @errors > 0 or @failures > 0 ) ]' );
108+
$testsuites = $xml->xpath( '//testsuites//testsuite[ ( count( testcase ) > 0 ) and ( @errors > 0 or @failures > 0 ) ]' );
109109
foreach ( $testsuites as $testsuite ) {
110-
// Handle nested testsuites like tests with data providers.
111-
$testsuite = isset( $testsuite->testsuite ) ? $testsuite->testsuite : $testsuite;
112110
$result = array(
113111
'name' => (string) $testsuite['name'],
114112
'tests' => (string) $testsuite['tests'],
@@ -118,19 +116,22 @@ function process_junit_xml( $xml_string )
118116
if ( empty( $result['failures'] ) && empty( $result['errors'] ) ) {
119117
continue;
120118
}
121-
$results['testsuites'][ (string) $testsuite['name'] ] = $result;
122-
$results['testsuites'][ (string) $testsuite['name'] ]['testcases'] = array();
119+
$failures = array();
123120
foreach ( $testsuite->testcase as $testcase ) {
124121
// Capture both failure and error children.
125122
foreach ( array( 'failure', 'error') as $key ) {
126123
if ( isset( $testcase->{$key} ) ) {
127-
$results['testsuites'][ (string) $testsuite['name'] ]['testcases'][ (string) $testcase['name'] ] = array(
124+
$failures[ (string) $testcase['name'] ] = array(
128125
'name' => (string) $testcase['name'],
129126
$key => (string) $testcase->{$key},
130127
);
131128
}
132129
}
133130
}
131+
if ( $failures ) {
132+
$results['testsuites'][ (string) $testsuite['name'] ] = $result;
133+
$results['testsuites'][ (string) $testsuite['name'] ]['testcases'] = $failures;
134+
}
134135
}
135136

136137
return json_encode( $results );

0 commit comments

Comments
 (0)