# Craft pest

> Craft pest is an open-source agent skill for developer tools. Gives agents a safe Pest workflow for testing Craft CMS 5 plugins without touching live. It is available on Claude Code.

- **Kind:** Skill
- **Pricing:** Open source
- **Platforms:** Claude Code
- **Website:** https://github.com/michtio/craftcms-claude-skills/tree/main/skills/craft-pest
- **Repository:** https://github.com/michtio/craftcms-claude-skills
- **GitHub stars:** 91
- **License:** MIT
- **Skill name:** craft-pest
- **Collection:** https://github.com/michtio/craftcms-claude-skills
- **Categories:** [developer tools](https://ai-powered.com/categories/developer-tools)
- **Listing updated:** 2026-12-03

## About

This skill guides an agent through writing, running and reviewing Pest tests for Craft CMS 5 plugins and modules using the markhuot/craft-pest-core harness. Its main focus is test isolation: making sure suites wrap writes in a rollback transaction, pin a dedicated test database and environment, and refuse to run against the wrong database. It also covers the bootstrap and phpunit.xml.dist wiring, timezone pinning, per-test site fixtures, idempotent install migrations, and CI jobs.

The skill is organised around a set of reference files covering isolation, Craft internals that affect tests (such as permission caching, login simulation and muted audit or event surfaces), general test patterns, shared-install concerns and CI wiring. It includes a checklist for reviewing an existing plugin suite and warns against running a suite through a shared project root, where plugin-level environment pins would be ignored.

Users need a Craft CMS 5 plugin or module, Pest with craft-pest-core, and a database the tests can safely use. A small shell script reports the Craft version of the current project.

## When your agent uses it

> Testing Craft CMS 5 plugins and modules with Pest: test isolation, database safety, and the markhuot/craft-pest-core harness. ALWAYS load when writing, running, fixing, or reviewing tests for a Craft plugin or module, and whenever a suite touches a real Craft install. Covers opt-in rollback, tests/Pest.php + tests/bootstrap.php wiring, phpunit.xml.dist <env> pins (DB name, table prefix, connection, CRAFT_ENVIRONMENT against server-scoped locks), why --configuration= defeats isolation, fail-closed DB guards, installing the plugin under test, timezone pinning, per-test site fixtures, idempotent Install migrations, stale service caches, audit sinks, queue stubs, factories, HTTP/DB assertions, CI jobs.

## What it can access

From a static check of the files on GitHub; nothing was run.

- [Runs shell scripts](https://github.com/michtio/craftcms-claude-skills/tree/HEAD/skills/craft-pest)
- [Asks for: Bash(sh ${CLAUDE_SKILL_DIR}/scripts/craft-version.sh)](https://github.com/michtio/craftcms-claude-skills/blob/HEAD/skills/craft-pest/SKILL.md)
- [No network calls found in its scripts](https://github.com/michtio/craftcms-claude-skills/tree/HEAD/skills/craft-pest)
- [License: MIT](https://github.com/michtio/craftcms-claude-skills/tree/HEAD/skills/craft-pest)

## Features

- **Database isolation setup:** Covers rollback transactions, forced test database names and fail-closed bootstrap guards so tests cannot write to a live install.
- **PHPUnit environment pinning:** Explains which phpunit.xml.dist env entries to set so suites use unique environment locks and table prefixes.
- **Craft state handling:** Addresses permission caching, simulated logins, muted audit and event surfaces, and stale service caches.
- **Test writing patterns:** Describes factories, HTTP and database assertions, queue stubs, multi-site fixtures and pure unit tests.
- **CI job guidance:** Explains how to run a Pest job in CI from the plugin root and verify it against a fresh database.
- **Install migration hygiene:** Shows how to make Install migrations idempotent so repeated runs do not accumulate duplicate keys.

## Good for

- Set up Pest tests for a new Craft CMS 5 plugin
- Stop a test suite from writing thousands of entries into a dev database
- Fix a test that passes alone but fails when the full suite runs
- Add a Pest job to a plugin's GitHub Actions workflow
- Test a controller action or element factory in a Craft plugin

## Install

### Claude Code

This skill ships in the `craftcms-claude-skills` plugin. In Claude Code, add the marketplace and install the plugin (it may include other skills too):

```sh
/plugin marketplace add michtio/craftcms-claude-skills
/plugin install craftcms-claude-skills@craftcms-claude-skills
```

Or copy only this skill to `~/.claude/skills/craft-pest`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/michtio/craftcms-claude-skills.git "$tmp" &&
mkdir -p ~/.claude/skills &&
rm -rf ~/.claude/skills/craft-pest &&
cp -R "$tmp/skills/craft-pest" ~/.claude/skills/craft-pest &&
rm -rf "$tmp"
```

For one project only, put the folder in `.claude/skills/craft-pest` inside it instead.

### Codex

Copy the skill folder to `~/.agents/skills/craft-pest` to use it in every repository:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/michtio/craftcms-claude-skills.git "$tmp" &&
mkdir -p ~/.agents/skills &&
rm -rf ~/.agents/skills/craft-pest &&
cp -R "$tmp/skills/craft-pest" ~/.agents/skills/craft-pest &&
rm -rf "$tmp"
```

For one repository only, put the folder in `.agents/skills/craft-pest` inside it instead.

### Cursor

Copy the skill folder to `~/.cursor/skills/craft-pest` to use it in every project:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/michtio/craftcms-claude-skills.git "$tmp" &&
mkdir -p ~/.cursor/skills &&
rm -rf ~/.cursor/skills/craft-pest &&
cp -R "$tmp/skills/craft-pest" ~/.cursor/skills/craft-pest &&
rm -rf "$tmp"
```

For one project only, put the folder in `.cursor/skills/craft-pest` inside it instead.

### Gemini CLI

Run in a terminal (add `--scope workspace` to install it for the current workspace only):

```sh
gemini skills install https://github.com/michtio/craftcms-claude-skills.git --path skills/craft-pest
```

Or copy the folder to `~/.gemini/skills/craft-pest` yourself.

### VS Code

For GitHub Copilot in VS Code, copy the skill folder to `~/.copilot/skills/craft-pest`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/michtio/craftcms-claude-skills.git "$tmp" &&
mkdir -p ~/.copilot/skills &&
rm -rf ~/.copilot/skills/craft-pest &&
cp -R "$tmp/skills/craft-pest" ~/.copilot/skills/craft-pest &&
rm -rf "$tmp"
```

For one project only, put the folder in `.github/skills/craft-pest` inside it instead.

### Other agents

Get the folder:

```sh
git clone --depth 1 https://github.com/michtio/craftcms-claude-skills.git
```

Then copy `craftcms-claude-skills/skills/craft-pest` into your agent's skills folder as `craft-pest`. Agents that support SKILL.md read one folder per skill.

## FAQ

### What does the skill need to be useful?

It needs a Craft CMS 5 plugin or module that uses Pest with the markhuot/craft-pest-core harness. It reads the Craft version from the project when the script runs.

### Why must RefreshesDatabase be bound alongside TestCase?

TestCase alone does not open a transaction, so writes made during tests are committed permanently. RefreshesDatabase is the trait that starts a transaction and rolls it back on teardown.

### Where should a plugin's test suite be run from?

From the plugin's own root directory. Running it with a --configuration flag from a shared project root means the plugin's environment pins are not loaded.

### Which languages and tools are involved?

The tests are written in PHP with Pest and the craft-pest-core package. The skill's helper script is a shell script run through the Claude Code allowed tools.

### How do I install Craft pest in Claude Code?

Copy the skill folder from GitHub to ~/.claude/skills/craft-pest to use it in all your projects, or to .claude/skills/craft-pest in one project. Or install the craftcms-claude-skills plugin, which includes it: /plugin marketplace add michtio/craftcms-claude-skills, then /plugin install craftcms-claude-skills@craftcms-claude-skills.

### Does Craft pest run scripts?

Yes. It runs shell scripts. No network calls were found in its scripts. This comes from a static check of the files on GitHub; nothing was run. Read the files before you install it.

### Which AI agents can use Craft pest?

Claude Code. It reads skills in the SKILL.md format; the install steps on this page show where to put the folder.

### What are the best alternatives to Craft pest?

The closest alternatives to Craft pest are Craftcms, Testing wp, Craft plugin release, Craft php guidelines and Craft gated build.

## Where this comes from

- Description: from the skill's own SKILL.md.

## Alternatives

- [Craftcms](https://ai-powered.com/skills/craftcms): Craftcms is an open-source agent skill for developer tools.
- [Testing wp](https://ai-powered.com/skills/testing-wp): Testing wp is an open-source agent skill for developer tools.
- [Craft plugin release](https://ai-powered.com/skills/craft-plugin-release): Craft plugin release is an open-source agent skill for developer tools.
- [Craft php guidelines](https://ai-powered.com/skills/craft-php-guidelines): Craft php guidelines is an open-source agent skill for developer tools.
- [Craft gated build](https://ai-powered.com/skills/craft-gated-build): Craft gated build is an open-source agent skill for developer tools.
- [Testing assistant](https://ai-powered.com/skills/testing-assistant): Testing assistant is an open-source agent skill for developer tools.
- [Craft plugins](https://ai-powered.com/skills/craft-plugins): Craft plugins is an open-source agent skill for developer tools.
- [Moodle phpunit testing](https://ai-powered.com/skills/moodle-phpunit-testing): Moodle phpunit testing is an open-source agent skill for developer tools.

---
Source: https://ai-powered.com/skills/craft-pest
