Testing with doubles
So far, we tested classes that are quite isolated; that is, they do not have much interaction with other classes. Nevertheless, we have classes that use several classes, such as controllers. What can we do with these interactions? The idea of unit tests is to test a specific method and not the whole code base, right?
PHPUnit allows you to mock these dependencies; that is, you can provide fake objects that look similar to the dependencies that the tested class needs, but they do not use code from those classes. The goal of this is to provide a dummy instance that the class can use and invoke its methods without the side effect of what these invocations might have. Imagine as an example the case of the models: if the controller uses a real model, then when invoking methods from it, the model would access the database each time, making the tests quite unpredictable.
If we use a mock as the model instead, the controller can invoke its methods as many times as needed without...