Mocking WordPress Objects
Mocking calls to wpdb
, WP_Query
, etc. can be done using the Mockery framework. While this isn't part of WP Mock itself, complex code will often need these objects and this framework will let you incorporate those into your tests. Since WP Mock requires Mockery, it should already be included as part of your installation.
An example with WPDB
WPDB
Let's say we have a function that gets three post IDs from the database.
When we mock the $wpdb
object, we're not performing an actual database call, only mocking the results. We need to call the get_col
method with an SQL statement, and return three arbitrary post IDs.
Last updated