PHPUnit for WordPress

Testing labAdvanced

Testing the plugin's logic functions; they can be run inside a WordPress test environment.

Steps

  1. Install PHPUnit with Composer.

  2. Separate the logic into testable functions.

  3. Write tests for sanitising and validation.

Example · php
public function test_sanitize_title() {
    $this->assertSame( 'hello-world', my_plugin_slug( 'Hello World' ) );
}
Prompt
Write PHPUnit tests for the plugin's sanitising and validation functions.

Sources

  1. PHPUnit Documentation