mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Fixes to TestRunner for latest PHPUnit/PHP
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.2.2@51452 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
12475f1b31
commit
5a05634c2d
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package sapphire
|
||||
* @subpackage testing
|
||||
@ -34,19 +33,11 @@ if(ManifestBuilder::staleManifest()) ManifestBuilder::compileManifest();
|
||||
require_once(MANIFEST_FILE);
|
||||
*/
|
||||
|
||||
|
||||
// Check that PHPUnit is installed
|
||||
$hasPhpUnit = false;
|
||||
$paths = explode(PATH_SEPARATOR, ini_get('include_path'));
|
||||
foreach($paths as $path) {
|
||||
if(@file_exists("$path/PHPUnit/Framework.php")) $hasPhpUnit = true;
|
||||
}
|
||||
|
||||
if($hasPhpUnit) {
|
||||
|
||||
/**
|
||||
*/
|
||||
if(hasPhpUnit()) {
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case class for the Sapphire framework.
|
||||
@ -139,7 +130,11 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
|
||||
$parsedItems[] = $this->parseFixtureVal($item);
|
||||
}
|
||||
$obj->write();
|
||||
$obj->getComponents($fieldName)->setByIDList($parsedItems);
|
||||
if($obj->many_many($fieldName)) {
|
||||
$obj->getManyManyComponents($fieldName)->setByIDList($parsedItems);
|
||||
} else {
|
||||
$obj->getComponents($fieldName)->setByIDList($parsedItems);
|
||||
}
|
||||
|
||||
} else {
|
||||
$obj->$fieldName = $this->parseFixtureVal($fieldVal);
|
||||
@ -172,20 +167,13 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
|
||||
// Delete our temporary database
|
||||
$dbConn = DB::getConn();
|
||||
if($dbConn && substr($dbConn->currentDatabase(),0,5) == 'tmpdb') {
|
||||
// echo "Deleted temp database " . $dbConn->currentDatabase() . "\n";
|
||||
$dbConn->dropDatabase();
|
||||
$dbName = $dbConn->currentDatabase();
|
||||
if($dbName && DB::query("SHOW DATABASES LIKE '$dbName'")->value()) {
|
||||
// echo "Deleted temp database " . $dbConn->currentDatabase() . "\n";
|
||||
$dbConn->dropDatabase();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// Stub
|
||||
/**
|
||||
* @ignore
|
||||
* @package sapphire
|
||||
* @subpackage testing
|
||||
*/
|
||||
class SapphireTest extends Object {}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -6,18 +6,20 @@
|
||||
*/
|
||||
|
||||
// Check that PHPUnit is installed
|
||||
$hasPhpUnit = false;
|
||||
$paths = explode(PATH_SEPARATOR, ini_get('include_path'));
|
||||
foreach($paths as $path) {
|
||||
if(@file_exists("$path/PHPUnit/Framework.php")) $hasPhpUnit = true;
|
||||
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;
|
||||
}
|
||||
|
||||
if($hasPhpUnit) {
|
||||
|
||||
/**
|
||||
*/
|
||||
if(hasPhpUnit()) {
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
require_once 'PHPUnit/TextUI/TestRunner.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Controller that executes PHPUnit tests
|
||||
@ -29,10 +31,14 @@ class TestRunner extends Controller {
|
||||
* Run all test classes
|
||||
*/
|
||||
function index() {
|
||||
$tests = ClassInfo::subclassesFor('SapphireTest');
|
||||
array_shift($tests);
|
||||
if(hasPhpUnit()) {
|
||||
$tests = ClassInfo::subclassesFor('SapphireTest');
|
||||
array_shift($tests);
|
||||
|
||||
$this->runTests($tests);
|
||||
$this->runTests($tests);
|
||||
} else {
|
||||
echo "Please install PHPUnit using pear";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -66,21 +72,8 @@ class TestRunner extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
* @package sapphire
|
||||
* @subpackage testing
|
||||
*/
|
||||
class TestRunner extends Controller {
|
||||
function index() {
|
||||
echo "Please install PHPUnit using pear.";
|
||||
}
|
||||
}
|
||||
|
||||
// This class is here to help with documentation.
|
||||
|
||||
if(!hasPhpUnit()) {
|
||||
/**
|
||||
* PHPUnit is a testing framework that can be installed using PEAR.
|
||||
* It's not bundled with Sapphire, you will need to install it yourself.
|
||||
@ -91,5 +84,4 @@ class TestRunner extends Controller {
|
||||
class PHPUnit_Framework_TestCase {
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user