From 5a05634c2dc167008eed3a5965d351764cf9cf04 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Wed, 19 Mar 2008 04:25:30 +0000 Subject: [PATCH] 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 --- testing/SapphireTest.php | 36 ++++++++++++------------------------ testing/TestRunner.php | 40 ++++++++++++++++------------------------ 2 files changed, 28 insertions(+), 48 deletions(-) diff --git a/testing/SapphireTest.php b/testing/SapphireTest.php index 2c4277ad4..2d0e11e2c 100644 --- a/testing/SapphireTest.php +++ b/testing/SapphireTest.php @@ -1,5 +1,4 @@ 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 {} -} - ?> diff --git a/testing/TestRunner.php b/testing/TestRunner.php index 7c0147206..6be658949 100644 --- a/testing/TestRunner.php +++ b/testing/TestRunner.php @@ -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 { } - } \ No newline at end of file