Hello, today I am experimenting with unit testing functions, on codeigniter, but that does not matter, the same question is for everything in PHP, or maybe not only in PHP, but general with functions that connect to database.
So lets say I have such function:
public function turnview_by_franchise_id($franchises_id, $clients_id, $date_from, $date_to, $shops_id) {
$shops_param = "";
if (!empty($shops_id)) {
$shops_param = " AND shops.id = '" . $shops_id . "' ";
}
$sql = "blah blah blah sql";
$result = $this->db->query($sql, array($franchises_id, $clients_id, $date_from, $date_to));
return $result->result_array();
}
Ok this function returns two dimentional array, or return empty array if there is no resutls. How can I test it? I could find parameters in my local database which would return something, the array would not be empty. But database data changes, so it easily can become empty. So I will not be able to test, unless I will update testing function everytime data in database changes. Also this will not work on another computer, for example my colegues, because he will have different data in database.
Or I should just test if returned data is_array and thats it?
Also another question - here as you can see the $sql itself is nonsene, so it would throw sql errors right to the screen, and I would not get any report - like passed or failed. I will know it has failed, but are unit tests made that way? Aren't they meant to return - fail pass, instead of actuall errros?