As you might know, currently I'm writing a lot of tests.

While we are not fan of the 100% Code Coverage dogma, we are trying to cover our code as much as possible.
Using namespaces, containers and dependency injections helps a lot, however there are some edge cases where you really can't test it.

I'm talking about PHP native functions: how can you simulate a specific time? Or if there is a problem while opening a file?

Please consider the following example code (obviously this code is pretty useless, it's just to have an handy example) :
class Timer
    public function getCurrentTime()
        return time();
As you can see the function getCurrentTime directly calls the native time() function of PHP, how am I supposed to check its result?
Well, we have several options:
  • using a PHP extension
  • extracting native functions and wrapping them inside another class
  • using namespaces