Let’s run the starter test suite to ensure everything is setup and ready to go. Then we’ll walk through the test suite basics.
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.
Integration Bootstrap – Defining Constants
Notes | Transcript | Code | Playlist Notes Next, we need to define the constants we’ll need as the baseline for directory locations. Transcript Code
Integration Bootstrap – Register Theme & Load
Notes | Transcript | Code | Playlist Notes We’re almost done with the bootstrap file. Whew! Right? In this episode, you and I will finish it. We need to: Load the WordPress tests suite’s includes/bootstrap.php file. Register a callback to the tests “theme_setup” event. When that event fires, we want to define where our themes directory is and switch the default theme to our theme. Finally, let’s load WordPress’ testing suite. Transcript Code
Integration Bootstrap – Overview
Notes | Transcript | Code | Playlist Notes In this episode, we’ll start laying out the steps to bootstrap our integration tests. Transcript Code
Wrap it Up
WooHoo! You did it! You made it through this lab. In doing so, you setup your testing environment, learned a few new things about Composer, dove into the formula for figuring out what to test, and wrote real unit and integration tests. Congratulations for completing this lab!
Integration Tests – Write Real Tests
Notes | Transcript | Code | Playlist Notes Let’s write a real test together. Remember back in an earlier episode where I told you that I found a bug in beans_replace_action() and beans_replace_action_hook()? Let’s write the test for that bug. You’ll get using the added functionality from WordPress’ Test Case, as you’ll create a new post and use the go_to() method. Transcript Code
Meet WP_UnitTestCase
Notes | Transcript | Playlist Notes WordPress packages a bunch of functionality for us to use in our integration tests. You extend off of the WP_UnitTestCase to gain access to things like: Factory for creating post content (i.e. posts, pages, and custom post types), terms, users, etc.) Loading a URL via go_to() Query tests to check that you did load the right stuff Setup for the query, global states, etc. Resets to return us to that original setup state, query, etc. Let’s talk about it in this episode. Transcript
Setup Local’s Web Server
Notes | Transcript | Playlist Notes Are you running Local by Flywheel, like me? If no, you can skip this episode. But if yes, then in this episode, you and I will install the packages we need as well as get WordPress setup. It’s really easy as Kees Meijer already has the bash script and instructions ready for you. Click here to get the script. Transcript
Setup Test Shortcuts in Composer
Notes | Transcript | Code | Playlist Notes In this episode, you’ll be: Installing all of the dependencies specified by running composer install. Fixing a namespace error in the composer.json file. Adding in the integration tests PSR-4 configuration. Adding in the scripts, which will make your testing job so much easier. Transcript Code
Create the Composer.json File
Notes | Transcript | Code | Playlist Notes In this episode, you and I will create a composer.json file to configure all of the dependencies we will need for our testing suites. Transcript Code