Skip to content

Testing

For testing our WP-FastEndpoints router we are going to use pest/php.

Pest is a testing framework that makes it super easy to test functionality in PHP, that's why we are going to use it here. However, if you have a preference for some other testing framework, the some principles should apply 😊

Full source code can be found at matapatos/wp-fastendpoints-my-plugin Β»

Testing dependencies

First, let's add all the necessary testing dependencies:

composer require mockery/mockery --dev  # For mocking classes/functions
composer require dingo-d/wp-pest --dev  # Adds Pest support for integration tests

Testing structure

For testing our plugin, we are going to assume the following structure:

my-plugin
β”‚   my-plugin.php
β”‚   composer.json
β”‚
└───src
β”‚       (...)
β”‚
└───tests
    β”‚   bootstrap.php   # Loads WordPress for integration tests
    β”‚   Helpers.php     # (optional) Helper functions
    β”‚   Pest.php        # Pest configuration file
    β”‚
    └───Integration
    β”‚       PostsApiTest.php
    β”‚
    └───Unit
            PostsApiTest.php