Skip to content

Commit

Permalink
[project @ Add a text-based test harness]
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Hoyt committed Dec 24, 2005
1 parent d6c42a8 commit 6accef2
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 10 deletions.
18 changes: 8 additions & 10 deletions test.php → Tests/TestDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,18 @@ function loadTests($test_dir, $test_names) {
return $suites;
}

// Load OpenID library tests
$test_dir = 'Tests/Net/OpenID/';
$test_names = array(
$_test_dir = 'Tests/Net/OpenID/';
$_test_names = array(
'KVForm',
'CryptUtil',
'DiffieHellman',
'HMACSHA1',
);

$suites = loadTests($test_dir, $test_names);

// Create and run the user interface
$gui = new PHPUnit_GUI_HTML();
$gui->addSuites($suites);
$gui->show();

// Load OpenID library tests
function loadSuite() {
global $_test_names;
global $_test_dir;
return loadTests($_test_dir, $_test_names);
}
?>
89 changes: 89 additions & 0 deletions texttest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

require_once('Tests/TestDriver.php');
require_once('PHPUnit/TestResult.php');

class TextTestResult extends PHPUnit_TestResult {
function addError(&$test, &$t) {
parent::addError($test, $t);
echo "E";
}

function addFailure(&$test, &$t) {
parent::addFailure($test, $t);
echo "F";
}

function addPassedTest(&$test) {
parent::addPassedTest($test);
echo ".";
}

function dumpBadResults() {
foreach ($this->failures() as $failure) {
echo $failure->toString();
}

foreach ($this->errors() as $failure) {
echo $failure->toString();
}
}
}

function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}

$suites = loadSuite();

$totals = array(
'run' => 0,
'error' => 0,
'failure' => 0,
'time' => 0
);

foreach ($suites as $suite) {
$name = $suite->getName();
echo "==========================================
Test suite: $name
------------------------------------------
";

$result = new TextTestResult();
$before = microtime_float();
$suite->run($result);
$after = microtime_float();

$run = $result->runCount();
$error = $result->errorCount();
$failure = $result->failureCount();
$delta = $after - $before;
$totals['run'] += $run;
$totals['error'] += $error;
$totals['failure'] += $failure;
$totals['time'] += $delta;
$human_delta = round($delta, 3);
echo "\nRan $run tests in $human_delta seconds";
if ($error || $failure) {
echo " with $error errors, $failure failures";
}
echo "
==========================================
";
}

$before = microtime_float();
$run = $totals['run'];
$error = $totals['error'];
$failure = $totals['failure'];
$time = round($totals['time'], 3);
echo "Ran a total of $run tests in $time seconds with $error errors, $failure failures\n";
if ($totals['error'] || $totals['failure']) {
exit(1);
}

?>
12 changes: 12 additions & 0 deletions webtest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

require_once('Tests/TestDriver.php');

$suites = loadSuite();

// Create and run the user interface
$gui = new PHPUnit_GUI_HTML();
$gui->addSuites($suites);
$gui->show();

?>

0 comments on commit 6accef2

Please sign in to comment.