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
This commit is contained in:
Sam Minnee 2009-05-05 22:21:27 +00:00
parent 8c9b7b282c
commit 2263aaa573
3 changed files with 18 additions and 3 deletions

View File

@ -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";

View File

@ -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.

View File

@ -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));