I Created a Free Dockerized WordPress Dev Setup For Integration Testing

Posted on:

So, I've been working on a super secret project that I'm not ready to talk about yet ????. This project is a very complex project that is utilizing several custom made composer packages. Different versions of the software end up getting compiled using several packages. With this workflow, I end up with a very adaptable system, where I can compile different dependencies together to build different versions of the system, which I very much need for this setup. The consequence of this is that my code ends up being fragmented across dozens of different composer packages. As you can imagine, this quickly became very cumbersome to work with.

Another challenge was that each package has its own set of unit tests, but I also needed a comprehensive way to implement integration tests between packages.

What I needed was a local dev environment that would solve these problems, as well as a few other things:

  1. I wanted to be able to natively use XDebug inside my IDE
  2. I wanted to be able to natively use PHPUnit inside my IDE
  3. I wanted a way to modify files across different packages, and instantly see the results, instead of needing to do any weird push/pull composer update song-and-dance.
  4. I wanted this to have as few dependencies as possible.

Based on this, I created a Docker-based setup that:

  1. Uses docker-compose to set up a complete local WordPress environment.
  2. The WordPress environment is customized to include PHPUnit and XDebug
  3. The localhost points to an accessible location from outside the container
  4. Unit tests use the same environment, so I can stop early to "freeze" the site in a specific state for testing purposes.
  5. All of my packages remain in their own github repository, and composer uses those files directly.
  6. Automatically runs integration tests when a pull request is submitted against it. (Assuming you're on GitHub)

I've really struggled over the years to find a good local WordPress setup, and I think I finally have something that I love. It's been incredibly effective, fast, and adaptable to not only my specific plugin scenario, but with a few tweaks to the script, can be used to set up a local environment for just about any WordPress setup.

This is one of about a dozen or so WordPress-friendly (see - not WordPress specific) packages that I've made over the last few months. I haven't decided if I'm going to share the rest of these packages or not yet. Even if I am, they're not quite ready for prime-time, anyway. I might share more details on that in a future update.

Anyway, here's the repository template. Give it a try sometime.