]> granicus.if.org Git - php/commitdiff
Fix junit XML format
authorAnatol Belski <ab@php.net>
Sat, 2 Dec 2017 09:40:43 +0000 (10:40 +0100)
committerAnatol Belski <ab@php.net>
Sat, 2 Dec 2017 09:40:43 +0000 (10:40 +0100)
The junit XML format is purely documented, some existings spec like
http://llg.cubic.org/docs/junit/ also provide an XSD. The testsuite
tag included into itself doesn't seems to be correct, instead only a
flat list is included into "testsuites" tag.

run-tests.php

index 75c4d6e50ddc9d6defb3e9f8874727d7e631afb4..aa75244b7493618f2d7c193c49fc78a1638ff40d 100755 (executable)
@@ -2768,8 +2768,12 @@ function junit_save_xml() {
        global $JUNIT;
        if (!junit_enabled()) return;
 
-       $xml = '<' . '?' . 'xml version="1.0" encoding="UTF-8"' . '?' . '>'. PHP_EOL .
-                  '<testsuites>' . PHP_EOL;
+       $xml = '<' . '?' . 'xml version="1.0" encoding="UTF-8"' . '?' . '>'. PHP_EOL;
+    $xml .= sprintf(
+               '<testsuites name="%s" tests="%s" failures="%d" errors="%d" skip="%d" time="%s">' . PHP_EOL,
+        $JUNIT['name'], $JUNIT['test_total'], $JUNIT['test_fail'], $JUNIT['test_error'], $JUNIT['test_skip'],
+               $JUNIT['execution_time']
+       );
        $xml .= junit_get_suite_xml();
        $xml .= '</testsuites>';
        fwrite($JUNIT['fp'], $xml);
@@ -2778,26 +2782,23 @@ function junit_save_xml() {
 function junit_get_suite_xml($suite_name = '') {
        global $JUNIT;
 
-       $suite = $suite_name ? $JUNIT['suites'][$suite_name] : $JUNIT;
-
-    $result = sprintf(
-               '<testsuite name="%s" tests="%s" failures="%d" errors="%d" skip="%d" time="%s">' . PHP_EOL,
-        $suite['name'], $suite['test_total'], $suite['test_fail'], $suite['test_error'], $suite['test_skip'],
-               $suite['execution_time']
-       );
+       $result = "";
 
-       foreach($suite['suites'] as $sub_suite) {
-               $result .= junit_get_suite_xml($sub_suite['name']);
-       }
+       foreach ($JUNIT['suites'] as $suite_name => $suite) {
+               $result .= sprintf(
+                       '<testsuite name="%s" tests="%s" failures="%d" errors="%d" skip="%d" time="%s">' . PHP_EOL,
+                       $suite['name'], $suite['test_total'], $suite['test_fail'], $suite['test_error'], $suite['test_skip'],
+                       $suite['execution_time']
+               );
 
-       // Output files only in subsuites
-       if (!empty($suite_name)) {
-               foreach($suite['files'] as $file) {
-                       $result .= $JUNIT['files'][$file]['xml'];
+               if (!empty($suite_name)) {
+                       foreach($suite['files'] as $file) {
+                               $result .= $JUNIT['files'][$file]['xml'];
+                       }
                }
-       }
 
-       $result .= '</testsuite>' . PHP_EOL;
+               $result .= '</testsuite>' . PHP_EOL;
+       }
 
        return $result;
 }