|
From: Jason S. <jsw...@ya...> - 2004-01-31 19:13:41
|
in my write test -> fail -> write code -> pass cycles, the first thing that
happens where I write a new method is that the test dies with a php fatal error
because the method does not exist. Using this assertion I can write a test
that verifies the method exists, see it fail, add the method to the class I am
testing, see the test pass and then move on to real relevant tests of the
method.
/**
* Confirms that a particular method is defined for a class.
* @param string $class the class to test
* @param string $method the name of the method to test
* @param string $message optional - Message to display.
* @access public
*/
function AssertMethodExists($class, $method, $message=false) {
if (!class_exists($class)) {
$this->Fail("'$class' is not a class");
}
if (false === $message) {
$message = "$class::$method() does not exist.";
}
if (is_callable(array($class, $method))) {
$this->Pass($message);
} else {
$this->Fail($message);
}
}
or perhaps I am just being pedantic?
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/
|