From 2263aaa57325ebe0e82b2a382e0c669b1a1bec71 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Tue, 5 May 2009 22:21:27 +0000 Subject: [PATCH] BUGFIX: Fixed text runner for PHP 5.1 API CHANGE: Added FunctionalTest::logInAs() to simplify logging in for tests. git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@76115 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- dev/CliTestReporter.php | 5 ++++- dev/FunctionalTest.php | 14 +++++++++++++- dev/TestRunner.php | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/dev/CliTestReporter.php b/dev/CliTestReporter.php index e902397bc..35fdd89b5 100644 --- a/dev/CliTestReporter.php +++ b/dev/CliTestReporter.php @@ -30,7 +30,10 @@ class CliTestReporter extends SapphireTestReporter { echo SSCli::text(" AT LEAST ONE FAILURE ", "white", "red"); } echo "\n\n$testCount tests run: " . SSCli::text("$passCount passes", null) . ", ". SSCli::text("$failCount fails", null) . ", and 0 exceptions\n"; - echo "Maximum memory usage: " . number_format(memory_get_peak_usage()/(1024*1024), 1) . "M\n\n"; + + if(function_exists('memory_get_peak_usage')) { + echo "Maximum memory usage: " . number_format(memory_get_peak_usage()/(1024*1024), 1) . "M\n\n"; + } $totalTime = array_sum($this->testSpeeds); echo "Total time: " . round($totalTime,3) . " seconds\n"; diff --git a/dev/FunctionalTest.php b/dev/FunctionalTest.php index 45ee853c7..b58689295 100644 --- a/dev/FunctionalTest.php +++ b/dev/FunctionalTest.php @@ -251,7 +251,19 @@ class FunctionalTest extends SapphireTest { . "Instead the following elements were found:\n'" . implode("'\n'", $actuals) . "'" ); } - } + } + + /** + * Log in as the given member + * @param $member The ID, fixture codename, or Member object of the member that you want to log in + */ + function logInAs($member) { + if(is_object($member)) $memberID = $member->ID; + elseif(is_numeric($member)) $memberID = $member; + else $memberID = $this->idFromFixture('Member', $member); + + $this->session()->inst_set('loggedInAs', $memberID); + } /** * Use the draft (stage) site for testing. diff --git a/dev/TestRunner.php b/dev/TestRunner.php index 81f2fdcc5..74675d045 100644 --- a/dev/TestRunner.php +++ b/dev/TestRunner.php @@ -123,7 +123,7 @@ class TestRunner extends Controller { function only($request) { $className = $request->param('TestCase'); if(class_exists($className)) { - if(!(singleton($className) instanceof SapphireTest)) { + if(!is_subclass_of($className, 'SapphireTest')) { user_error("TestRunner::only(): Invalid TestCase '$className', cannot find matching class", E_USER_ERROR); } $this->runTests(array($className));