bobmatnyc/claude-mpm-skills/wordpress-testing-qa

Claude Code and agent skill by bobmatnyc/claude-mpm-skills

Trust tier 2
  • community
  • ext:[{"type":"hook","description":"Pre/post lifecycle hooks"},{"type":"config","description":"Configuration overrides"}]
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

WordPress plugin and theme testing with PHPUnit integration tests, WP_Mock unit tests, PHPCS coding standards, and CI/CD workflows

Install

npx vskill@latest install bobmatnyc/claude-mpm-skills/wordpress-testing-qa

Semi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard

SKILL.md

The same SKILL.md was published earlier as bobmatnyc/claude-mpm-skills/wordpress-testing-qa.

WordPress Testing & Quality Assurance


progressive_disclosure: entry_point: summary: "WordPress plugin and theme testing with PHPUnit, WP_Mock, PHPCS, and CI/CD for quality assurance" when_to_use:

  • "Testing WordPress plugins with PHPUnit integration tests"
  • "Unit testing without loading WordPress core (WP_Mock)"
  • "Enforcing coding standards with PHPCS"

quick_start:

  • "Set up PHPUnit with WordPress test suite"
  • "Write unit tests with WP_Mock"
  • "Configure PHPCS with WPCS ruleset"

Testing Strategy

Testing Pyramid for WordPress

The WordPress Testing Hierarchy:

/\
/ \ E2E Tests (Playwright)
/ \ - Full user workflows
/------\ - Browser automation
/ \
/ INTEG \ Integration Tests (PHPUnit + WordPress)
/ TESTS \ - Database operations
/ \ - Hook interactions
--------------
UNIT TESTS Unit Tests (WP_Mock)
- Pure logic
- No WordPress dependency

Test Distribution Guidelines:

  • Unit Tests (60%): Fast, isolated, no WordPress
  • Pure PHP functions
  • Class methods with clear inputs/outputs
  • Business logic without side effects
  • Integration Tests (30%): WordPress-loaded tests
  • Database operations
  • Hook/filter interactions
  • Custom post type registration
  • Settings API functionality
  • E2E Tests (10%): Browser automation
  • Critical user workflows
  • Admin panel interactions
  • Frontend form submissions
When to Use PHPUnit vs WP_Mock

Use PHPUnit (Integration Tests) when:

  • ✅ Testing database operations ($wpdb, post creation, meta data)
  • ✅ Testing WordPress hooks (actions/filters actually firing)
  • ✅ Testing template rendering and output
  • ✅ Testing plugin activation/deactivation logic
  • ✅ Testing with actual WordPress functions

Use WP_Mock (Unit Tests) when:

  • ✅ Testing pure business logic
  • ✅ Testing functions that call WordPress functions but logic is independent
  • ✅ Need fast test execution (no database setup)
  • ✅ Testing in isolation without side effects
  • ✅ Mocking external API calls
Test Coverage Goals

Minimum Coverage Requirements:

  • New Code: 80% minimum coverage
  • Critical Paths: 95% coverage (payment processing, authentication, data validation)
  • Legacy Code: Gradual improvement, prioritize high-risk areas
  • Public APIs: 100% coverage for all public methods

What to Test (Priority Order):

  1. Security Functions: Nonce verification, sanitization, capability checks
  2. Data Operations: Database CRUD, data validation, transformation
  3. Business Logic: Calculations, workflows, state transitions
  4. Hook Callbacks: Action/filter handlers
  5. Public APIs: REST endpoints, WP-CLI commands

What NOT to Test:

  • ❌ WordPress core functions (assume they work)
  • ❌ Third-party library internals
  • ❌ Simple getters/setters with no logic
  • ❌ Configuration files (theme.json, block.json)

PHPUnit Integration Testing

WordPress Test Suite Setup

Step 1: Install Dependencies

bash
# Install PHPUnit and WordPress polyfills
composer require --dev phpunit/phpunit "^9.6"
composer require --dev yoast/phpunit-polyfills "^2.0"
# Generate test scaffold with WP-CLI
wp scaffold plugin-tests my-plugin
# This creates:
# - tests/bootstrap.php
# - tests/test-sample.php
# - phpunit.xml.dist
# - bin/install-wp-tests.sh

Step 2: Install WordPress Test Library

bash
# Install WordPress test suite and test database
# Syntax: bash bin/install-wp-tests.sh <db-name> <db-user> <db-pass> <db-host> <wp-version>
bash bin/install-wp-tests.sh wordpress_test root '' localhost latest
# For specific WordPress version:
bash bin/install-wp-tests.sh wordpress_test root '' localhost 6.7

Step 3: Configure phpunit.xml.dist

xml
<?xml version="1.0"?>
<phpunit
bootstrap="tests/bootstrap.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false"
>
<testsuites>
<testsuite name="plugin">
<directory prefix="test-" suffix=".php">./tests/</directory>
<exclude>./tests/bootstrap.php</exclude>
</testsuite>
</testsuites>
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">./includes/</directory>
</include>
<exclude>
<directory>./vendor/</directory>
<directory>./tests/</directory>
</exclude>
<report>
<html outputDirectory="coverage-html"/>
<text outputFile="php://stdout" showOnlySummary="true"/>
</report>
</coverage>
<php>
<const name="WP_TESTS_PHPUNIT_POLYFILLS_PATH" value="vendor/yoast/phpunit-polyfills"/>
</php>
</phpunit>
WP_UnitTestCase Base Class

tests/bootstrap.php:

php
<?php
/**
* PHPUnit bootstrap file
*/
// Composer autoloader
require_once dirname(__DIR__) . '/vendor/autoload.php';
// WordPress tests directory
$_tests_dir = getenv('WP_TESTS_DIR');
if (!$_tests_dir) {
$_tests_dir = rtrim(sys_get_temp_dir(), '/\\') . '/wordpress-tests-lib';
}
if (!file_exists("{$_tests_dir}/includes/functions.php")) {
throw new Exception("Could not find {$_tests_dir}/includes/functions.php");
}
// Give access to tests_add_filter() function
require_once "{$_tests_dir}/includes/functions.php";
/**
* Manually load the plugin being tested
*/
function _manually_load_plugin() {
require dirname(__DIR__) . '/my-plugin.php';
}
tests_add_filter('muplugins_loaded', '_manually_load_plugin');
// Start up the WordPress testing environment
require "{$_tests_dir}/includes/bootstrap.php";
Factory Objects for Test Data

Using Built-in Factories:

php
<?php
class Test_Plugin_Integration extends WP_UnitTestCase {
/**
* Test creating posts with factory
*/
public function test_create_post_with_meta() {
// Create a post using factory
$post_id = $this->factory->post->create([
'post_title' => 'Test Post',
'post_content' => 'Test content for integration test',
'post_status' => 'publish',
'post_type' => 'post',
]);
$this->assertIsInt($post_id);
$this->assertGreaterThan(0, $post_id);
// Add post meta
add_post_meta($post_id, '_custom_field', 'custom_value');
// Verify meta was saved
$meta_value = get_post_meta($post_id, '_custom_field', true);
$this->assertEquals('custom_value', $meta_value);
}
/**
* Test creating users
*/
public function test_user_can_edit_post() {
// Create editor user
$editor_id = $this->factory->user->create([
'role' => 'editor',
'user_login' => 'test_editor',
'user_email' => 'editor@example.com',
]);
// Set as current user
wp_set_current_user($editor_id);
// Create post
$post_id = $this->factory->post->create([
'post_author' => $editor_id,
]);
// Test capabilities
$this->assertTrue(current_user_can('edit_post', $post_id));
$this->assertTrue(current_user_can('edit_posts'));
$this->assertFalse(current_user_can('manage_options'));
}
/**
* Test creating terms and taxonomy
*/
public function test_assign_categories() {
// Create category
$category_id = $this->factory->category->create([
'name' => 'Test Category',
'slug' => 'test-category',
]);
// Create post
$post_id = $this->factory->post->create();
// Assign category
wp_set_post_categories($post_id, [$category_id]);
// Verify assignment
$categories = wp_get_post_categories($post_id);
$this->assertContains($category_id, $categories);
}
/**
* Test creating comments
*/
public function test_post_has_comments() {
$post_id = $this->factory->post->create();
// Create multiple comments
$comment_ids = $this->factory->comment->create_many(3, [
'comment_post_ID' => $post_id,
'comment_approved' => 1,
]);
$this->assertCount(3, $comment_ids);
// Get comments for post
$comments = get_comments(['post_id' => $post_id]);
$this->assertCount(3, $comments);
}
}

Available Factory Objects:

  • $this->factory->post - Posts, pages, custom post types
  • $this->factory->user - Users with roles
  • $this->factory->term - Terms (categories, tags, custom taxonomies)
  • $this->factory->category - Categories specifically
  • $this->factory->tag - Tags specifically
  • $this->factory->comment - Comments
  • $this->factory->blog - Multisite blogs
Database Fixtures and Teardown

setUp() and tearDown() Methods:

php
<?php
class Test_Custom_Post_Type extends WP_UnitTestCase {
protected $post_ids = [];
/**
* Setup runs before EACH test method
*/
public function setUp(): void {
parent::setUp();
// Register custom post type
register_post_type('book', [
'public' => true,
'supports' => ['title', 'editor'],
]);
// Create test data
$this->post_ids = $this->factory->post->create_many(5, [
'post_type' => 'book',
]);
}
/**
* Teardown runs after EACH test method
*/
public function tearDown(): void {
// Clean up test data
foreach ($this->post_ids as $post_id) {
wp_delete_post($post_id, true); // Force delete
}
// Unregister post type
unregister_post_type('book');
parent::tearDown();
}
/**
* Test that books are created
*/
public function test_books_created() {
$this->assertCount(5, $this->post_ids);
$query = new WP_Query([
'post_type' => 'book',
'posts_per_page' => -1,
]);
$this->assertEquals(5, $query->found_posts);
}
}

setUpBeforeClass() and tearDownAfterClass():

php
<?php
class Test_Plugin_Database extends WP_UnitTestCase {
protected static $table_name;
/**
* Runs ONCE before all tests in class
*/
public static function setUpBeforeClass(): void {
parent::setUpBeforeClass();
global $wpdb;
self::$table_name = $wpdb->prefix . 'plugin_data';
// Create custom table
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE " . self::$table_name . " (
id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
user_id bigint(20) unsigned NOT NULL,
data_value varchar(255) NOT NULL,
created_at datetime DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
KEY user_id (user_id)
) $charset_collate;";
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
dbDelta($sql);
}
/**
* Runs ONCE after all tests in class
*/
public static function tearDownAfterClass(): void {
global $wpdb;
$wpdb->query("DROP TABLE IF EXISTS " . self::$table_name);
parent::tearDownAfterClass();
}
/**
* Test table exists
*/
public function test_custom_table_exists() {
global $wpdb;
$table_exists = $wpdb->get_var(
"SHOW TABLES LIKE '" . self::$table_name . "'"
);
$this->assertEquals(self::$table_name, $table_exists);
}
/**
* Test insert data
*/
public function test_insert_data() {
global $wpdb;
$result = $wpdb->insert(
self::$table_name,
[
'user_id' => 1,
'data_value' => 'test_value',
],
['%d', '%s']
);

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
58
Repository forks
19
7-day trend score
20

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Extension points

  • hookPre/post lifecycle hooks
  • configConfiguration overrides

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/bobmatnyc/claude-mpm-skills/wordpress-testing-qa/badge)](https://verified-skill.com/skills/bobmatnyc/claude-mpm-skills/wordpress-testing-qa)

Something wrong with this skill or its page? Tell us.