A short while ago I wrote a set of three PHP unit tests for Math that use test doubles to
stub out external dependencies (in this case, the database-backed cache and the texvc
executable). My intent was to demonstrate the technique to another developer, so I
commented the code extensively. It occurred to me that other people might be interested,
too, so I'm sharing it here.
The advantage of such tests is that they typically faster and far less brittle than tests
that rely on external resources. They also make test results less noisy: if the test
fails, you know that it's because your code was wrong, and not because the database
happened to suffer an outage. Finally, they are more portable, because they don't
require that you configure external dependencies to make them work.
If you are interested, check out the example, and the relevant chapter in the PHPUnit
docs.
https://gerrit.wikimedia.org/r/#/c/49612/1/tests/MathTexvcTest.php
http://www.phpunit.de/manual/current/en/test-doubles.html
--
Ori Livneh