Until I started at Thismoment, I had never written unit tests.  Then I wrote a few that used a database.  The poor cleanup functions would litter our test sites with junk.

Until I started at Bigcommerce, I had never written unit tests with mocks.  They hurt my brain for a while, until I figured out what they were doing and why they were important.  And how to read the error messages that PHPUnit spits out.  Can’t forget that one.  It turns out, trying to use things without a reasonable grasp of them is difficult, time consuming, and plain NOT FUN.

When I found this series of posts while looking for resources on PHP unit testing, I wished I could go back in time and read it before all of that heartache.  It’s an excellent tutorial on PHPUnit basics, why we use test mocks (things like avoiding calling external APIs, testing only one thing at a time, etc.), and what kinds of things you want to think about when testing.

Related Posts