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.
Let’s build the centralized data, state, and configuration parameters store in an Object Oriented (OOP) architecture. What You Will Learn X Prerequisites See the list of prerequisites and suggestions on the series landing page.
This is part 4 of the series. In this hands-on coding lab, you’ll build, test, and validate more advanced features for the data store, thereby extending its functionality and utility.
Before we can build the data store, we need to understand what it is we need to build. In this lab, you’ll think through each of the requirements, working to define what makes a store a store, how to interact with it, what functionality is needed, and conceptually how to achieve it, and then what approaches you’ll employ in the series.
How can you unit test your plugin or theme without WordPress or other dependencies? You simulate the dependencies. My favorite tool to redefine and mock functions is Brain Monkey. In this hands-on testing lab, you will write unit tests using Brain Monkey.
Let’s walk through the code challenge I gave to you in the last episode.
Let’s build another test to learn more about using with()
We can test that the arguments the mocked function receives are what we expect by using the with() method. Mockery, which is baked into Brain Monkey, inspects the received arguments and then tests each one against what you’ve defined it should receive. This feature allows us to ensure our code is properly doing its work and sending the right set of data to the function we are mocking. Here, let me show you.