A Pest plugin for WordPress

Overview

WordPress Pest Plugin

Supports integrating Pest with your WordPress code base through the Mantle Framework. Read about the Mantle Testing Framework here.

If you want to start testing your application with Pest, visit the main Pest Repository.

Pest was created by Nuno Maduro under the Sponsorware license. It got open-sourced and is now licensed under the MIT license.

Overview

The WordPress Pest Plugin allows WordPress to be tested using the Pest testing framework. Tests can be written in a very simple manner to 'bring the joy of testing to PHP'.

Example Test

Getting Started

The WordPress Pest Plugin does not require the Mantle Framework to be used on your site (though having the framework greatly enhances your ability to use Pest).

Install the WordPress plugin via the Composer package manager:

composer require alleyinteractive/pest-plugin-wordpress --dev

Setting up Pest

Note: if you are using the Mantle Framework, skip ahead to Using With the Mantle Framework.

Let's get started integrating your project with Mantle and Pest. This guide assumes that your project is placed inside an existing WordPress installation as a plugin or a theme. Read more information about setting up the test framework here.

The default configuration will install WordPress using a localhost database named wordpress_unit_tests with the username/password pair of root/root. All constants can be overridden using the wp-tests-config.php file or your unit test's bootstrap file.

Assuming you do not have Pest setup in your project, create a tests folder and run the pest --init command:

./vendor/bin/pest --init

Replacing the Pest Test Case

Open up the tests/Pest.php file in your project the above command created for you. Look for a line that looks like this:

// uses(Tests\TestCase::class)->in('Feature');

Replace that with the following:

uses(\Pest\PestPluginWordPress\FrameworkTestCase::class)->in(__DIR__);

// Install WordPress via Mantle.
\Mantle\Testing\install();

Finally, you can run Pest directly from the command line:

./vendor/bin/pest

You can now use the Mantle Testing Framework with Pest to test your WordPress plugin with ease and simplicity. Your IDE will be able to type-hint you as well to allow you to use the testing framework.

Using With the Mantle Framework

Requiring the WordPress Pest Plugin on an existing Mantle project will allow you to install Pest with a few commands.

Install the WordPress plugin via the Composer package manager and run the mantle pest:install WP-CLI command:

composer require alleyinteractive/pest-plugin-wordpress --dev

wp mantle pest:install

That's it! Pest is installed successfully on you Mantle project. You can run your pest tests through Pest now:

./vendor/bin/pest

Mantle can also generate a Pest-friendly test by running the pest:test WP-CLI command:

wp mantle pest:test <TestName>

Writing Tests

More information can be found on the Testing Framework page.

use function Pest\PestPluginWordPress\from;
use function Pest\PestPluginWordPress\get;

it( 'should load the homepage', function () {
    get( '/' )
        ->assertStatus( 200 )
        ->assertSee( 'home' );
} );

it( 'should load with a referrer', function () {
    from( 'https://laravel.com/' )
        ->get( '/' )
        ->assertStatus( 200 );
});
You might also like...
🚀WordPress Plugin Boilerplate using modern web techs like TypeScript, SASS, and so on... on top of a local development environment with Docker and predefined GitLab CI for continous integration and deployment!
🚀WordPress Plugin Boilerplate using modern web techs like TypeScript, SASS, and so on... on top of a local development environment with Docker and predefined GitLab CI for continous integration and deployment!

WP React Starter: WordPress React Boilerplate DEPRECATED: WP React Starter was a "research project" of devowl.io for the development of our WordPress

a wordpress plugin that improves wpgraphql usage together with wpml

WPGraphQL WPML Extension Contributors: rburgst Stable tag: 1.0.6 Tested up to: 5.6.1 Requires at least: 4.9 Requires PHP: 7.0 Requires WPGraphQL: 0.8.

A WordPress plugin for JAMstack deployments
A WordPress plugin for JAMstack deployments

JAMstack Deployments A WordPress plugin for JAMstack deployments on Netlify (and other platforms). Description This plugin provides a way to fire off

WordPress Plugin for Magic
WordPress Plugin for Magic

Login by Magic This plugin replaces the standard WordPress login form with one powered by Magic that enables passwordless email magic link login. Plea

âť“ A WordPress plugin to display your site's environment type in the admin bar

Where A WordPress plugin to display your site's environment type in the admin bar. Available Filters where_env_should_add_env_type - Defaults to true

Wordpress Plugin for displaying content from Notion

notion-content Description Wordpress Plugin for displaying content from Notion using the Notion API. This plugin assumes you have some knowledge of No

WordPress plugin that allows admin to force logout all users

User Login Control User Login Control is a WordPress plugin allows you to logout user(s) from their account or to see the last activity of your offlin

 WordPress plugin people can use to embed to their website:  a Mintbase NEAR NFT  and  Mintbase NEAR store
WordPress plugin people can use to embed to their website: a Mintbase NEAR NFT and Mintbase NEAR store

mintbase-embed WordPress plugin people can use to embed to their website: a Mintbase NEAR NFT and Mintbase NEAR store This is demo plugin that allows

WPCloudDeploy is a WordPress plugin that allows you to easily deploy servers at major cloud-server providers and then install apps
WPCloudDeploy is a WordPress plugin that allows you to easily deploy servers at major cloud-server providers and then install apps

WPCloudDeploy is a WordPress plugin that allows you to easily deploy servers at major cloud-server providers and then install apps

Comments
Releases(v0.4.0)
Owner
Alley Interactive
Let's do launch.
Alley Interactive
A WordPress plugin to suspend WordPress sites automagically. Simple and lightweight, no annoying ads and fancy settings.

Suspend WP A WordPress plugin to suspend WordPress sites automagically. Simple and lightweight, no annoying ads and fancy settings. ?? Demo (coming so

Waren Gonzaga 3 Nov 15, 2021
WordPress plugin that lets you use Discourse as the community engine for a WordPress blog

WP Discourse Note: the wp-discourse plugin requires >= PHP-5.4.0. The WP Discourse plugin acts as an interface between your WordPress site and your Di

Discourse 497 Dec 10, 2022
Simple WordPress plugin to learn how to understand WordPress Crons and the Action Scheduler library.

Simple WordPress plugin to learn how to understand WordPress Crons and the Action Scheduler library. Import Jamendo playlists with tracks in WordPress posts.

Pierre Saikali 3 Dec 7, 2022
This WordPress Plugin Boilerplate is meant for you to develop your own plugin on.

WordPress Plugin Boilerplate This plugin boilerplate is meant for you to develop your own plugin on. Support & collaboration Features OOP plugin core

richardev 2 May 10, 2022
A custom WordPress nav walker class to fully implement the Twitter Bootstrap 4.0+ navigation style (v3-branch available for Bootstrap 3) in a custom theme using the WordPress built in menu manager.

WP Bootstrap Navwalker This code in the main repo branch is undergoing a big shakeup to bring it in line with recent standards and to merge and test t

WP Bootstrap 3.3k Jan 5, 2023
A curated list of Awesome WordPress Theme, Plugins and Framework development Resources and WordPress Communities.

Awesome WordPress A curated list of Awesome WordPress Theme, Plugins and Framework development Resources and WordPress Communities. Inspired by bayand

Dropndot Limited 91 Dec 26, 2022
Twenty Twenty-Two, the default WordPress theme that will launch with WordPress 5.9.

Twenty Twenty-Two Welcome to the development repository for the default theme that will launch with WordPress 5.9. About Twenty Twenty-Two is designed

null 414 Nov 28, 2022
Easy handle APlayer on WordPress. A shortcode for WordPress to using APlayer.

Description Easy handle APlayer on WordPress. A shortcode for WordPress to using APlayer. Support [audio] tag, compatible with AMP. Requirement WordPr

Karl Chen 24 Nov 3, 2022
WordPress & TypeScript. Simple starter template for WordPress projects

WordPress & TypeScript. Simple starter template for WordPress projects that want to use TypeScript in combination with @wordpress/scripts

Make it WorkPress 11 Sep 27, 2022
A PHP client for Wordpress websites that closely implement the XML-RPC WordPress API

Wordpress XML-RPC PHP Client A PHP client for Wordpress websites that closely implement the XML-RPC WordPress API Created by Hieu Le MIT licensed. Cur

Hieu Le 112 Nov 10, 2022