2007-08-15 08:38:41 +02:00
|
|
|
<?php
|
|
|
|
|
2008-01-08 07:37:50 +01:00
|
|
|
/**
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage testing
|
|
|
|
*/
|
|
|
|
|
2007-08-15 12:01:35 +02:00
|
|
|
// Check that PHPUnit is installed
|
2008-03-19 21:38:52 +01:00
|
|
|
function hasPhpUnit() {
|
|
|
|
$paths = explode(PATH_SEPARATOR, ini_get('include_path'));
|
|
|
|
foreach($paths as $path) {
|
|
|
|
if(@file_exists("$path/PHPUnit/Framework.php")) return true;
|
|
|
|
}
|
|
|
|
return false;
|
2007-08-15 12:01:35 +02:00
|
|
|
}
|
|
|
|
|
2008-01-09 05:18:36 +01:00
|
|
|
/**
|
|
|
|
*/
|
2008-03-19 21:38:52 +01:00
|
|
|
if(hasPhpUnit()) {
|
2007-08-15 08:38:41 +02:00
|
|
|
require_once 'PHPUnit/Framework.php';
|
|
|
|
require_once 'PHPUnit/TextUI/TestRunner.php';
|
2008-03-19 21:38:52 +01:00
|
|
|
}
|
2007-08-15 08:38:41 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Controller that executes PHPUnit tests
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package sapphire
|
|
|
|
* @subpackage testing
|
2007-08-15 08:38:41 +02:00
|
|
|
*/
|
|
|
|
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() {
|
2008-03-19 21:38:52 +01:00
|
|
|
if(hasPhpUnit()) {
|
|
|
|
$tests = ClassInfo::subclassesFor('SapphireTest');
|
|
|
|
array_shift($tests);
|
2007-08-15 08:38:41 +02:00
|
|
|
|
2008-03-19 21:38:52 +01:00
|
|
|
$this->runTests($tests);
|
|
|
|
} else {
|
|
|
|
echo "Please install PHPUnit using pear";
|
|
|
|
}
|
2007-08-16 08:35:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
2008-01-08 03:12:18 +01:00
|
|
|
// Ensure that the autoloader pulls in the test class, as PHPUnit won't know how to do this.
|
|
|
|
class_exists($className);
|
2007-08-16 08:35:27 +02:00
|
|
|
$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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-10 01:33:18 +01:00
|
|
|
// This class is here to help with documentation.
|
2008-03-19 21:38:52 +01:00
|
|
|
if(!hasPhpUnit()) {
|
2008-01-10 01:33:18 +01:00
|
|
|
/**
|
|
|
|
* PHPUnit is a testing framework that can be installed using PEAR.
|
|
|
|
* It's not bundled with Sapphire, you will need to install it yourself.
|
|
|
|
*
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage testing
|
|
|
|
*/
|
|
|
|
class PHPUnit_Framework_TestCase {
|
|
|
|
|
|
|
|
}
|
2007-08-15 08:38:41 +02:00
|
|
|
}
|