UnionOfRAD/lithium — pull request #814 by BlaineSch (2013-02-06 02:45:59+00:00)
Title: Give `Mocker` the ability to stub global function calls.

This is more of a trick, since calling a funciton like `get_called_class()` in a namespace is first searched for in the current namespace, then globally. Here, we simply create it in the same namespace it's called allowing users to overwrite the return value of it. The user defined function can be overwritten, and if deleted will result in the global function being called normally.

Often times we make methods that call php-defined methods such as `define`, `compact`, `eval`, `json_decode`, `token_get_all`, and the list goes on. Often it's best to stub the php-defined functions to manipulate the behavior of the method, but putting a giant list of php-defined functions in a config variable is not very elegant and would start making your code harder to read, and doing so for testing seems a bit over the top.

This pull request provides a simple and reset-able api to allow stubbing of functions.

For example, nobody wants to create a new file for each test (starting to sound like a factory vs fixture debate...) so you could stub some functions like so:

~~~ php

~~~

~~~ php
assertNotEqual(0, $results['users'][0]['updated']);
}
}

?>
~~~