Skip to content

Instantly share code, notes, and snippets.

@ngunyimacharia
Last active February 25, 2025 14:45
Show Gist options
  • Select an option

  • Save ngunyimacharia/916d0f9237bc6f86d9c579e7a020fad0 to your computer and use it in GitHub Desktop.

Select an option

Save ngunyimacharia/916d0f9237bc6f86d9c579e7a020fad0 to your computer and use it in GitHub Desktop.
PHPUnit `report.xml` analysis
<?php
$xmlFile = 'report.xml'; // Update with the actual XML file path
if ( ! file_exists($xmlFile)) {
die("Error: PHPUnit report file not found.\n");
}
$xml = simplexml_load_file($xmlFile);
foreach ($xml->testsuite as $suite) {
foreach ($suite->testsuite as $subSuite) {
foreach ($subSuite->testsuite as $testcase) {
$name =
(string) $testcase['classname'].'::'.(string) $testcase['name'];
$time = (float) $testcase['time'];
$tests[$name] = $time;
}
}
}
arsort($tests); // Sort by time in descending order
echo "All PHPUnit Tests Ordered by Duration:\n";
foreach ($tests as $test => $time) {
echo "$test - $time sec\n";
}
@ngunyimacharia
Copy link
Author

Report generated using ./vendor/bin/phpunit --log-junit report.xml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment