1
0
mirror of synced 2025-02-20 22:23:14 +03:00

[2.0] Added jpgraph.php script that can be used to visualize logs of phpunit test runs with graphs using jpgraph. The graphs show the performance of tests over the revisions.

This commit is contained in:
romanb 2009-10-05 21:19:19 +00:00
parent e4e1291b6a
commit 27d8873ae7

90
jpgraph.php Normal file
View File

@ -0,0 +1,90 @@
<?php
// If you dont have jpgraph, you need to download it from:
// http://www.aditus.nu/jpgraph/jpdownload.php
$jpgraphPath = '../lib/jpgraph-3.0.3/src'; // put the path to your jpgraph install here
// ------------------------------------------
require_once "$jpgraphPath/jpgraph.php";
require_once "$jpgraphPath/jpgraph_line.php";
$logsPath = 'logs/';
$revisions = array();
$graphs = array();
if (isset($_POST['test'])) {
list($testsuite, $testcase) = explode('#', $_POST['test']);
}
$items = scandir($logsPath);
foreach ($items as $item) {
if ($item[0] != '.') {
$revisions[] = $item;
}
}
foreach ($revisions as $rev) {
$xml = simplexml_load_file($logsPath . $rev . '/log.xml');
foreach ($xml->testsuite as $suite) {
foreach ($suite->testcase as $test) {
$name = (string)$suite['name'] . '#' . (string)$test['name'];
$graphs[$name][] = (double)$test['time'];
}
}
}
if (isset($testsuite) && isset($testcase)) {
$graphName = $testsuite . '#' . $testcase;
$graphData = $graphs[$graphName];
// Create the graph. These two calls are always required
$graph = new Graph(650,250);
//$graph->SetScale('intint');
$graph->SetScale('textlin');
$graph->yaxis->scale->SetAutoMin(0);
$graph->title->Set($testsuite);
$graph->subtitle->Set($testcase);
$graph->xaxis->title->Set('revision');
$graph->yaxis->title->Set('seconds');
$graph->SetMargin(100, 100, 50, 50);
// Create the linear plot
$lineplot = new LinePlot($graphData);
$lineplot->SetColor('blue');
$graph->xaxis->SetTickLabels($revisions);
// Add the plot to the graph
$graph->Add($lineplot);
// Display the graph
$graph->Stroke();
} else {
echo '<html><head></head><body>';
echo 'Pick a test and click "show":<br/>';
echo '<form method="post" action="' . $_SERVER['PHP_SELF'] . '">';
echo '<select name="test">';
foreach ($graphs as $name => $data) {
echo '<option value="' . $name . '">' . $name . '</option>';
}
echo '</select>';
echo '<button type="submit">Show</button>';
echo '</form>';
echo '</body></html>';
}