Testing Framework? assertException? assertClassExists?
Posted: Sat Aug 12, 2006 4:03 pm
Not fully appreciating the "tests first, code later" principle of TDD, I have made full week's worth of changes to my code a tested a mere 2 functions. Needless to say I need to test it all now. No doubt you'll be seeing a fair bit of me in this thread over the next week or so (I hope I'm not still debugging this thing after that) as I encounter difficulties with testing. Anyway, I have three questions:
- So far I've been using SimpleTest by good ole' Marcus Baker (who I have met hehe
) but I'm wondering if it is the best around given that I am writing E_STRICT PHP 5 code and SimpleTest is anything but - How do you assertException or assertNoException? I want to test that a specific but of code has not thrown an exception at the moment I'm doing it like thisBut that could all be theorically be replaced by
Code: Select all
$toLoad = 'NonExistantClass'; try { OF::loadClass($toLoad); } catch (OF_Exception $e) {}; $this->assertNull($e); unset($e);assertNoException doesn't seem to exist so perhaps there is another way of doing it or will I have to add the method myself?Code: Select all
$this->assertNoException(OF::loadClass($toLoad)); - I am trying to test whether a class exists. At the moment I'm doing it like thisis that actually any good I don't know if I am extending it correctly, seems to work though.
Code: Select all
$toLoad = 'Text.php'; $toLoadChk = 'OF_' . $toLoad; $this->assertClassNotExist($toLoadChk); OF::loadClass($toLoad); $this->assertClassExists($toLoadChk); } function assertClassExists($value, $message = "%s") { $dumper = new SimpleDumper(); $message = sprintf( $message, "[" . $dumper->describeValue($value) . "] should be an existant class"); return $this->assertTrue(class_exists($value), $message); } function assertClassNotExist($value, $message = "%s") { $dumper = new SimpleDumper(); $message = sprintf( $message, "[" . $dumper->describeValue($value) . "] should be a non-existant class"); return $this->assertTrue(!class_exists($value), $message); }