|
From: Marcus B. <ma...@wo...> - 2008-08-18 21:16:26
|
Hi...
Mark Donohoe wrote:
> I also tried to have the above classes extend fossologyWebTestCase instead of
> WebTestCase, but still get the same failure?
> ...
This is going to nearly impossible to sort out via e-mail. Can you send
me an example failing test case, with as small amount of code as
necessary to duplicate your problem? I can debug it quickly and easily
if I can play with real code. Most of what you describe *should* work fine.
> What am I missing, how do I do this? Thanks for your time and help.
>
The project wide test case that Jason suggests is really for project
wide settings. I tend to use a different technique for composing test
behaviours.
Take a mail test helper...
class MailFixture {
function __construct($test) {
$this->test = $test
}
function setUp() { ... }
function tearDown() { ... }
function assertHas($email, $substring, $th = 1) { ... }
...
}
class TestingSomeMailStuff extends UnitTestCase {
function setUp() {
$this->mail()->setUp();
}
function tearDown() {
$this->mail()->tearDown();
}
function testMailWasSentOnNewPasswordRequest() {
$accounts = new MockAccounts();
$accounts->setReturnValue('getPassword', 'secret', array('me'));
$request = new Request(array('email' => 'me...@he...'
'username' => 'me'));
$controller = new ReminderController($request, $accounts);
$this->mail()->assertBody('me...@he...', ' secret ');
}
// This can go into your project wide test cases.
function mail() {
return new MailFixture($this);
}
}
Actually, in a real unit test I'd mock the Mailer as well, but bear with me.
The MailHelper (imported with require_once(dirname(__FILE__) ...)) can
be used anywhere. As it's only created when needed, and has no state, we
can move the factory method into your project wide test cases. This
makes the tests pretty clean, just adding a small function chain when
using these facilities.
Once I'm back on the SimpleTest code base again, we'll make this system
more automatic.
yours, Marcus
|