Pete's Log: Unit Testing for Fun (and not for Profit)

Entry #2427, (Coding, Hacking, & CS stuff, Meta)
(posted when I was 45 years old.)

One reason my rewrite of www.esgeroth.org stalled out is that I discovered that my "modern" php wasn't quite as modern as I had hoped for.

In particular, I ran into a wall because I was accessing php global state all over the place. That is, various classes were accessing superglobals such as $_SERVER or directly manipulating the response by calling header or generating output. These things make it difficult to properly unit test.

So I've started semi-fresh with a design that encapsulates all interaction with the php global state into a few dedicated classes. These I can then mock in unit tests.

The good news is my code coverage percentage is much higher than previously. The bad news is I only have a small subset of the site ported to this new system, so that higher percentage applies to a smaller set of code.

OK (61 tests, 187 assertions) Code Coverage Report: 2023-11-03 03:10:10 Summary: Classes: 77.27% (17/22) Methods: 85.11% (80/94) Lines: 78.33% (235/300)

It does feel like progress, but I still don't quite understand why I am doing this to myself. I should just go to bed.

In other news, the upgrade to php 7.4 has enabled me to bump the strictness level on phpstan from 4 to 8.