Let's unit test your code

Albert Albala

Whether you're maintaining Drupal 7 or Drupal 8 sites, or indeed any PHP project, including unit tests is now easier than ever. This talk is aimed at novice to intermediate developers, and requires some experience with PHP.

Unit tests are tests on your code's logic, not the GUI. They are fast, reliable, and promote good coding practices. In this talk we'll look at:

The test pyramid: why unit tests are cheaper to write and provide more value than integration or functional tests such as Behat
The basics of PHPUnit: mock objects, testing exceptions, expectations, test providers
Why it's important to write small functions that do one thing well
How you can move legacy procedural code into objects to make it testable
How to leverage Docker to run your tests locally and on a continuous integration server
Using GitHub and Circle CI as a continuous integration setup



To get the most of this talk, come prepared by:

Having a PHP project on GitHub
Opening a Circle CI account
Having Docker installed on your machine (requires Linux or post-2010 Macs)