views:

12

answers:

1

Hi, currently I'm using phpunit to write tests for some functions that access a mysql-database. Now I'm unsure what to do to distinguish when a function returns some datasets or nothing (which both are valid function results). Should I use different tests (so that one of them will fail in any case) or is it in this case ok to use an if that possibly skips asserts? I have to do some tests on the results, if there are some.

I know this has been asked before somewhere already, but I couldn't formulate a proper query to get me an answer, sorry.

A: 

You should have two tests, each one expecting different result: one expecting 0 (it indicates error or just no result), another one - dataset (can be dataset empty btw? and, on error, you have empty dataset or just null/false/0 whatever?)

you can use different queries or different fixtures sets to ensure different responses. You can also completly mock the response or use different dbs. It all depends of structure of your tests and app.

ts