PHPUnit Dramas

Nick Bennett

17/03/2014

  • PHP
  • Technology

A frail PHPUnit suite is one thing, but one that completely crashes MySQL is something else entirely!

I wanted to do a quick blog as this problem isn’t well documented and I want to save people the same pain I went through.

The problem manifested on a rather large suite of tests with a dedicated MySQL instance. When running the suite we were getting ‘database gone away’ errors in our DB unit tests. Our first thoughts were that it was potentially an issue with our out-of-date version of MySQL. Upon investigation, though it appeared the problem could be replicated and indeed fixed.

The problem seemed to be a number of things.

  1. Multiple table creation scripts for the same table (I know)
  2. Mixing up engine types for tables within the same database
  3. Having MySQL comment blocks in the table creation statements
  4. The use of set foreign constraints statement

After much pain, the suite was eventually restored to working order. The lesson learnt was to centralise all of the DB unit table creation scripts. This ensures 1 point of entry for changes and debugging.