I am trying to test a model, in this case a user model, but I find that
I cannot predict how the save method will behave. It seems that the
call to the database is not happening until the end of the script. So,
for example if I say:
// testing insert
function test1()
{
$data = array( // stuff here );
$this->assertTrue($this->user->save($data));
}
// testing fail to insert duplicate data
function test2()
{
$data = array( // same stuff here );
$this->assertFalse($this->user->save($data));
}
When I run the test I find that test2 failed, that true was returned.
So I look at the table and find that test2 did indeed insert data,
however more frustrating still is the fact that test1 did not insert
any data, but still returned true.
So, I tried to skip this test and instead test insert, fetch and
remove. Doing that yields the following test results...
run 1
insert ... success
fetch ... failure
remove ... success (this is strange because on run 2...)
run 2
insert ... failure
fetch ... success
remove ... success (how could it succeed both times?)
At any rate this is a cycle it goes through on each run, it strikes me
that the data isn't being saved the first time until after the script
runs, so remove is returning true because it succeeded in removing no
rows. Then on the second run the field is there so save fails, but
everything else succeeds. Any idea whether this is true, or how to
work around this for sane testing?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---