Finding Tests to Write
Photo by Clem Onojeghuo.
Once you’re comforable writing a basic test, you’ll want to find functions or lines of code which need tests. Don’t forget to review how to name your PHPT files.
The PHP gcov site shows which functions have tests in a number of ways and is broken down by version. You should write tests for the current stable branch of PHP, which is 7.1 at the time of this writing.
You can find tests to write by:
- Checking the coverage report for directories—which map to core or extensions—with low percentages, indicated by red or yellow cells. Reading the coverage report means understanding some C code to see how the function works. Searching for
PHP_METHODblocks that have lines in red will lead you to parts of the codebase in need of tests.
- Browsing the tested functions, which flag functions without tests in red. Then, review the documentation for the function on php.net to understand how it’s supposed to work and how to write a test for it.
- You can also look at test failures to try to fix an existing test, instead of writing a new one.
You shouldn’t spend time writing tests for extensions which are deprecated or have been removed, like ereg or mysql. If you’re using a pre-built testing environment like docker-phpqa, some extensions which need tests are disabled. In this case, you’ll need to setup a testing environment where you can enable extensions.