Time for a code challenge to make sure you now understand how when() works and how to use each of its different task options. Let’s write 4 different when() definitions for the WordPress function esc_html_e(). Then we’ll discuss how to select the best option as well as how to keep your code DRY.
Labs
Labs are hands-on coding projects that you build along with Tonya as she explains the code, concepts, and thought processes behind it. You can use the labs to further your code knowledge or to use right in your projects. Each lab ties into the Docx to ensure you have the information you need.
Each lab is designed to further your understanding and mastery of code. You learn more about how to think about its construction, quality, maintainability, programmatic and logical thought, and problem-solving. While you may be building a specific thing, Tonya presents the why of it to make it adaptable far beyond that specific implementation, thereby giving you the means to make it your own, in any context.
Lab Setup
In this episode, I’ll quickly go over what you will be doing in this lab. Then I’ll walk you through how to setup your environment for the lab. For this, you will want to: Setup a local website on your Mac or Windows machine. Navigate into your themes directory. Clone this repository, which gives you the theme we’ll use in the Testing Series. Navigate into the new theme. Install the Composer dependencies. Run composer test-unit to make sure everything works. You will need your local machine setup and ready to go. If you need help, go to either of these […]
Testing an Action Has a Callback
Testing a Callback is Registered to an Action Hook
Testing a Filter Fired
Brain Monkey’s Hook Toolset
The Problem – Why We Need to Simulate WordPress
Testing Hooks with Brain Monkey
Our themes and plugins use hooks to run code when an event fires. We use WordPress’ functions to add or remove a hooked callback, fire the event, or check the status. How do you unit test those interactions without loading WordPress? Meet Brain Monkey. Brain Monkey gives you the power to unit test hooks by simulating WordPress. In this lab, you’ll walk through building unit tests for hooks.