simpletest - Why does setReturnValue() seem to change behaviour depending whether test is run in iso

Posted by JW on Stack Overflow See other posts from Stack Overflow or by JW
Published on 2010-04-26T00:23:16Z Indexed on 2010/04/26 0:53 UTC
Read the original article Hit count: 373

Filed under:
|
|
|

I am using SimpleTest version 1.0.1 for a unit test.

I create a new mock object within a test method and on it i do:

$MockDbAdaptor->setReturnValue('query',1); 

Now, when i run this in a standalone unit test my tested object is happy to see 1 returned when query() is called on the mock db adaptor.

However, when this exact same test is run as part of my 'all_tests' TestSuite, the test is failing. This happens because a call to the mock's query() method does not appear to return any value - thus causing my test subject to complain and trigger an unexpected exception that fails the test.

So, the behaviour of setReturnValue() seems to change depending on whether the test is run in isolation or not.

I can get it to work in both a standalone and TestSuite contexts by using this instead:

$MockDbAdaptor->setReturnValueAt(0,'query',1);

So my immediate problem can be fixed ...but it feels like a hack.

I thought if i create a new mock within a test method then why is the setReturnValue() behaviour getting affected by the context in which the test class instance is run?

It feel like a bug.

© Stack Overflow or respective owner

Related posts about php

Related posts about simpletest