wp-phpunit-writing-tests

wp-phpunit-writing-tests is a skill for Claude Code, Codex from Lonsdale201/wp-agent-skills. It costs 205 tokens per session (2,777 once invoked), scanned A, original, MIT.

A guide to writing PHPUnit tests for WordPress plugins and themes. PHPUnit is a PHP testing tool, and these tests can run inside a real WordPress test installation or separately with mocked WordPress functions.

In plain words
What is it for?
Use it to write or review tests, create WordPress posts and other fixtures, mock HTTP requests or WordPress functions, and choose the right test type.
Why use it?
It helps avoid mixing integration tests with faster unit tests and explains how to create and clean up test data safely. It also clarifies what WordPress's test fixtures do and do not isolate.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it to write or review tests, create WordPress posts and other fixtures, mock HTTP requests or WordPress functions, and choose the right test type.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/lonsdale201/wp-agent-skills/wp-phpunit-writing-tests
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add Lonsdale201/wp-agent-skills --skill wp-phpunit-writing-tests
Clone the repo
git clone --depth 1 https://github.com/Lonsdale201/wp-agent-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for wp-phpunit-writing-tests

README.md
[![agentmods](https://agentmods.dev/badge/skills/lonsdale201/wp-agent-skills/wp-phpunit-writing-tests/github.svg)](https://agentmods.dev/skills/lonsdale201/wp-agent-skills/wp-phpunit-writing-tests)
Your own site
<a href="https://agentmods.dev/skills/lonsdale201/wp-agent-skills/wp-phpunit-writing-tests"><img src="https://agentmods.dev/badge/skills/lonsdale201/wp-agent-skills/wp-phpunit-writing-tests/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for wp-phpunit-writing-tests

Your own site · 80×15
<a href="https://agentmods.dev/skills/lonsdale201/wp-agent-skills/wp-phpunit-writing-tests"><img src="https://agentmods.dev/badge/skills/lonsdale201/wp-agent-skills/wp-phpunit-writing-tests.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 205 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,777 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00205 $0.02777
Opus 5 $0.00102 $0.01388
Sonnet 5 $0.00041 $0.00555
Haiku 4.5 $0.00020 $0.00278

Measured 10d ago against content hash 694ba9e5b51b, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-09, from the pricing page.

Security

Grade A, and why

wp-phpunit-writing-tests scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 10d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

dev-tooling/wp-phpunit-writing-tests/SKILL.md · 220 lines

How it starts

The opening of the file, as written. The whole thing — 220 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Writing WordPress PHPUnit tests

Once the harness is in place (wp-phpunit-test-setup), this skill is about the tests themselves: which base class, how to build fixtures, how to mock, and the integration-vs-unit decision that trips most people up.

When to use this skill

  • Writing the first real tests for a plugin/theme.
  • Reviewing tests for correct fixtures, isolation, and mocking.
  • Deciding between an integration test and a true unit test.
  • Mocking outbound HTTP (wp_remote_*) or WP functions.

Integration vs unit — get this right first

WP_UnitTestCase boots the full WordPress environment and uses a real test database. Its teardown and factory cleanup isolate normal WordPress records, but do not describe the suite as a universal per-test transaction: code that commits, creates tables/files, changes external services, starts cron workers, or mutates non-database globals still needs explicit cleanup. Despite the name, this is an integration test, not a pure unit test.

For true unit tests — fast, isolated, no WP boot, no DB — you mock WordPress functions with one of:

  • Brain Monkey (brain/monkey, 2.7.x) — Mockery + Patchwork based; expressive when() / expect().
  • WP_Mock (10up/wp_mock, 1.1.x) — explicit per-function expectations, action/filter helpers.

Rule of thumb: test your own logic (a calculator, a formatter, a class method) as a unit test with mocked WP calls; test interaction with WordPress (it really saved the post, the hook really ran) as a WP_UnitTestCase integration test. Most plugins want both, in separate test suites.

Integration tests: WP_UnitTestCase

Fixtures are snake_case — and that matters

class Test_My_Plugin extends WP_UnitTestCase {

    public function set_up(): void {
        parent::set_up();          // MUST be the first line
        // per-test arrange
    }

    public function tear_down(): void {
        // per-test cleanup
        parent::tear_down();       // MUST be the last line
    }

    public function test_it_does_a_thing(): void {
        $this->assertTrue( my_plugin_does_a_thing() );
    }
}

Read the full file on GitHub · 220 lines

Files

What ships with it

1 file beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 10d ago First seen · 220 lines · 205 tokens per session scan A 694ba9e5b51b

Subscribe to this mod's changes

wp-phpunit-writing-tests is a skill published in the GitHub repository Lonsdale201/wp-agent-skills (22 stars, last pushed 11d ago), licensed MIT. It adds 205 tokens to every session and 2,777 once invoked, about $0.0010 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

phpunit-testing

Guide for writing and running PHPUnit unit and integration tests for WP Rig theme components.

wprig/wprig · 16 tokens

laravel-testing

Test strategy for a layered Laravel application — which test style fits each layer, hand-written fakes over mocks, real-database tests for Query Classes and Repositories, pure tests for Value Objects, and feature tests that assert authorization, payload shape and query counts. Use when writing or reviewing Laravel…

Foysal50x/skills · 83 tokens

laravel-tdd

Drives Laravel feature development with Pest or PHPUnit — factories, RefreshDatabase, fakes for queues/mail/notifications, Sanctum auth, and Inertia assertions. Use when writing or fixing a Laravel controller, Eloquent model, policy, job, or notification, when the project uses Pest/PHPUnit, or when asked to test an…

shennawardana23/skillme · 78 tokens

pw-test

Use when creating, executing, or managing Pest tests within ProcessWire or ProcessWire modules, including Test-Driven Development (TDD) tasks.

trk/processwire-boost · 32 tokens

migrate-mstest-v3-to-v4

Use this skill before answering, planning, or editing any MSTest 3.x-to-4.x upgrade or post-upgrade failure. Triggers include "MSTest v4 breaking changes"; CS0507/CS0103/CS1061/CS1615; ExecuteAsync, CallerInfo, DisplayName, or custom TestMethodAttribute; ClassCleanupBehavior; ContainsKey; ThrowsExactly or…

managedcode/dotnet-skills · 179 tokens

migrate-xunit-to-mstest

Convert .NET tests from xUnit.net v2/v3 to MSTest v4 while preserving VSTest or MTP. Use for replacing xunit packages, Fact/Theory/InlineData/MemberData, assertions, IClassFixture/ICollectionFixture, ITestOutputHelper, TestContext cancellation, traits/Owner, skips, timeouts, and xUnit parallelization. Also use when a…

managedcode/dotnet-skills · 141 tokens