Possible Duplicate:
PHP - override existing function
I want to use mocking to unit test some of my functions that have external dependencies.
So here goes... Below is a simplified model of what I'm working with. A lot of the code I have inherited is written in this way, so I would like to be able to write some simple tests without having to rewrite if possible:
function display_tasks($id)
{
$tasks = call_some_function_that_runs_a_database_query($id);
$html = "<some html>";
foreach ($tasks as $task)
{
// Some operations here
}
$html .= "</some html>";
return $html;
}
The code that my function is calling is not wrapped in an object, so I am having trouble putting the various examples into practice, as 99% of the examples on the internet are based on object-oriented code. Is it even possible to mock procedural functions directly from PHPunit?
I would like to be able to mock out whatever call_some_function_that_runs_a_database_query
is returning. I have had a go at using the built-in PHPunit mocking methods, but doing this doesn't override the result from the original call in my function.
Any help or examples would be really appreciated.