2007-08-15 08:38:41 +02:00
|
|
|
<?php
|
|
|
|
|
2007-08-15 12:01:35 +02:00
|
|
|
// Check that PHPUnit is installed
|
|
|
|
$hasPhpUnit = false;
|
|
|
|
$paths = explode(PATH_SEPARATOR, ini_get('include_path'));
|
|
|
|
foreach($paths as $path) {
|
2007-08-20 05:50:57 +02:00
|
|
|
if(@file_exists("$path/PHPUnit/Framework.php")) $hasPhpUnit = true;
|
2007-08-15 12:01:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if($hasPhpUnit) {
|
|
|
|
|
2007-08-15 08:38:41 +02:00
|
|
|
require_once 'PHPUnit/Framework.php';
|
|
|
|
require_once 'PHPUnit/TextUI/TestRunner.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Controller that executes PHPUnit tests
|
|
|
|
*/
|
|
|
|
class TestRunner extends Controller {
|
2007-08-16 08:35:27 +02:00
|
|
|
/**
|
|
|
|
* Run all test classes
|
|
|
|
*/
|
2007-08-15 08:38:41 +02:00
|
|
|
function index() {
|
|
|
|
ManifestBuilder::includeEverything();
|
|
|
|
|
|
|
|
$tests = ClassInfo::subclassesFor('SapphireTest');
|
|
|
|
array_shift($tests);
|
|
|
|
|
2007-08-16 08:35:27 +02:00
|
|
|
$this->runTests($tests);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run only a single test class
|
|
|
|
*/
|
|
|
|
function only() {
|
|
|
|
$className = $this->urlParams['ID'];
|
|
|
|
if(class_exists($className)) {
|
|
|
|
$this->runTests(array($className));
|
|
|
|
} else {
|
|
|
|
echo "Class '$className' not found";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function runTests($classList) {
|
2007-08-15 08:38:41 +02:00
|
|
|
echo "<h1>Sapphire PHPUnit Test Runner</h1>";
|
2007-08-16 08:35:27 +02:00
|
|
|
echo "<p>Using the following subclasses of SapphireTest for testing: " . implode(", ", $classList) . "</p>";
|
2007-08-15 08:38:41 +02:00
|
|
|
|
|
|
|
echo "<pre>";
|
|
|
|
$suite = new PHPUnit_Framework_TestSuite();
|
2007-08-16 08:35:27 +02:00
|
|
|
foreach($classList as $className) {
|
|
|
|
$suite->addTest(new PHPUnit_Framework_TestSuite($className));
|
2007-08-15 08:38:41 +02:00
|
|
|
}
|
|
|
|
|
2007-08-16 08:35:27 +02:00
|
|
|
/*, array("reportDirectory" => "/Users/sminnee/phpunit-report")*/
|
|
|
|
PHPUnit_TextUI_TestRunner::run($suite);
|
2007-08-15 12:01:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
class TestRunner extends Controller {
|
|
|
|
function index() {
|
|
|
|
echo "Please install PHPUnit using pear.";
|
2007-08-15 08:38:41 +02:00
|
|
|
}
|
2007-08-15 12:01:35 +02:00
|
|
|
}
|
|
|
|
|
2007-08-15 08:38:41 +02:00
|
|
|
}
|