PHP code example of testmonitor / junit-xml-parser
1. Go to this page and download the library: Download testmonitor/junit-xml-parser library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
testmonitor / junit-xml-parser example snippets
use TestMonitor\JUnitXmlParser\JUnitXmlParser;
$parser = new JUnitXmlParser();
$testSuites = $parser->parse('path/to/junit.xml');
use TestMonitor\JUnitXmlParser\JUnitXmlParser;
$parser = new JUnitXmlParser();
$testSuites = $parser->parse('tests/results.xml');
foreach ($testSuites as $suite) {
echo "Suite: " . $suite->getName() . "\n";
foreach ($suite->getTestCases() as $testCase) {
echo " Test: " . $testCase->getName() . " - Status: " . $testCase->getStatus()->name . "\n";
}
}
use TestMonitor\JUnitXmlParser\JUnitXmlParser;
$parser = new JUnitXmlParser();
$testSuites = $parser->parse('tests/results.xml');
foreach ($testSuites as $suite) {
foreach ($suite->getTestCases() as $testCase) {
if ($testCase->getStatus() === TestStatus::FAILED) {
echo "Test " . $testCase->getName() . " failed: " . $testCase->getFailureMessage() . "\n";
} elseif ($testCase->getStatus() === TestStatus::SKIPPED) {
echo "Test " . $testCase->getName() . " was skipped.\n";
}
}
}
use TestMonitor\JUnitXmlParser\JUnitXmlParser;
$parser = new JUnitXmlParser();
$result = $parser->parse('tests/results.xml');
foreach ($result->getTestSuites() as $suite) {
echo "Suite: {$suite->getName()}\n";
foreach ($suite->getProperties() as $key => $value) {
echo "$key: $value\n";
}
}
use TestMonitor\JUnitXmlParser\JUnitXmlParser;
use TestMonitor\JUnitXmlParser\Enums\TestStatus;
$parser = new JUnitXmlParser();
$result = $parser->parse('tests/results.xml');
foreach ($result->getTestSuites() as $suite) {
foreach ($suite->getTestCases() as $testCase) {
if ($testCase->getStatus() === TestStatus::PASSED) {
echo "Test '{$testCase->getName()}' passed:\n";
echo $testCase->getSystemOut() . "\n\n";
} else {
echo "Test '{$testCase->getName()}' didn't pass:\n";
echo $testCase->getSystemErr() . "\n\n";
}
}
}
use TestMonitor\JUnitXmlParser\JUnitXmlParser;
$parser = new JUnitXmlParser();
$testSuites = $parser->parse('tests/results.xml');
foreach ($testSuites as $suite) {
echo "Suite: " . $suite->getName() . " executed in " . $suite->getDuration() . " seconds on " . $suite->getTimestamp() . "\n";
}