Introduction to PHP Unit Testing

The purpose of these lessons is to get a conceptual understanding of PHPUnit testing using WP_PHPUnit for WordPress plugins/themes. These lessons are aimed at beginner-to-intermediate-level developers who are familiar with the PHPUnit Framework.

Prerequisites ✅

  • Knowledge of WordPress Development
    • These lessons are aimed to help developers write unit tests for WordPress plugins/themes. It is a mandatory requisite to know at least basic WordPress development.
    • You can learn WordPress development from here: https://developer.wordpress.org/
  • Knowledge of writing a basic PHPUnit Test
    • As WP PHPUnit is built upon PHPUnit, we need to be familiar with the PHPUnit framework first in order to use the WP PHPUnit framework.
    • You can learn PHPUnit from here: https://phpunit.de/
  • Using Composer & NPM
    • Composer is a tool package manager for PHP frameworks/libraries like PHPUnit and WP PHPUnit
    • NPM is a package manager for JS frameworks/libraries.
    • Learn more about composer here: https://getcomposer.org/

Learn more about NPM here: https://www.npmjs.com/

Objectives 🎯

After completing these lessons, you will be able to:

  • Set up the WP PHPUnit testing environment for plugins/themes.
  • Choose the right test cases for WordPress plugins/themes.
  • Write unit tests for the plugin using the WP PHPUnit framework.
  • Write efficient & test-driven code.