# Moodle phpunit testing

> Moodle phpunit testing is an open-source agent skill for developer tools. Guides an agent to write, run and debug PHPUnit tests for Moodle plugins and core. It is available on Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose.

- **Kind:** Skill
- **Pricing:** Open source
- **Platforms:** Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf, Goose
- **Website:** https://github.com/SaadRahman01/claude-moodle-dev/tree/main/skills/moodle-phpunit-testing
- **Repository:** https://github.com/saadrahman01/claude-moodle-dev
- **GitHub stars:** 44
- **License:** MIT
- **Skill name:** moodle-phpunit-testing
- **Collection:** https://github.com/SaadRahman01/claude-moodle-dev
- **Categories:** [developer tools](https://ai-powered.com/categories/developer-tools)
- **Listing updated:** 2026-12-02

## About

This skill gives an agent working knowledge of Moodle's PHPUnit harness. It covers the standard test class layout built on the advanced test case base, using resetAfterTest for database isolation, and the conventions Moodle's coding style expects such as final classes and covers annotations.

The guidance walks through setting up the test environment with the Moodle init script, writing plugin data generators, and testing events, emails, scheduled and ad-hoc tasks, and external web service functions including return value cleaning. It also explains how to mock the database when integration tests are not practical, and lists common mistakes with their fixes.

The skill is a single SKILL.md with no bundled scripts. It expects a Moodle codebase with the phpunit tool installed and a configured test database, and it is aimed at PHP developers working on Moodle plugins or core.

## When your agent uses it

> Use when writing, running, or debugging PHPUnit tests for Moodle plugins or core. Covers advanced_testcase, resetAfterTest, data generators, mocking $DB, testing events/tasks/external functions, and CLI invocation.

## What it can access

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

- [Instructions only, no scripts](https://github.com/SaadRahman01/claude-moodle-dev/tree/HEAD/skills/moodle-phpunit-testing)
- [License: MIT](https://github.com/SaadRahman01/claude-moodle-dev/tree/HEAD/skills/moodle-phpunit-testing)

## Features

- **Test class structure:** Covers the file naming, base class, annotations and method signatures Moodle expects for test classes.
- **Data generators:** Shows how to add a plugin generator and call it from tests to create fixtures.
- **Event and task testing:** Explains capturing events and emails and running scheduled and ad-hoc tasks inside tests.
- **External function testing:** Describes testing web service functions and validating return values against their schema.
- **Running and debugging suites:** Lists CLI commands for running suites, files, single methods, groups and coverage, plus fixes for database errors.

## Good for

- Write PHPUnit tests for a new Moodle local plugin
- Debug a 'Database was modified' failure in a test
- Add a data generator for plugin fixtures
- Test an external web service function's return values
- Set up PHPUnit in a GitHub Actions workflow for Moodle

## Install

### Claude Code

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

```sh
/plugin marketplace add SaadRahman01/claude-moodle-dev
/plugin install moodle-dev@moodle-dev
```

Or copy only this skill to `~/.claude/skills/moodle-phpunit-testing`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/SaadRahman01/claude-moodle-dev.git "$tmp" &&
mkdir -p ~/.claude/skills &&
rm -rf ~/.claude/skills/moodle-phpunit-testing &&
cp -R "$tmp/skills/moodle-phpunit-testing" ~/.claude/skills/moodle-phpunit-testing &&
rm -rf "$tmp"
```

For one project only, put the folder in `.claude/skills/moodle-phpunit-testing` inside it instead.

### Codex

Copy the skill folder to `~/.agents/skills/moodle-phpunit-testing` to use it in every repository:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/SaadRahman01/claude-moodle-dev.git "$tmp" &&
mkdir -p ~/.agents/skills &&
rm -rf ~/.agents/skills/moodle-phpunit-testing &&
cp -R "$tmp/skills/moodle-phpunit-testing" ~/.agents/skills/moodle-phpunit-testing &&
rm -rf "$tmp"
```

For one repository only, put the folder in `.agents/skills/moodle-phpunit-testing` inside it instead.

### Cursor

Copy the skill folder to `~/.cursor/skills/moodle-phpunit-testing` to use it in every project:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/SaadRahman01/claude-moodle-dev.git "$tmp" &&
mkdir -p ~/.cursor/skills &&
rm -rf ~/.cursor/skills/moodle-phpunit-testing &&
cp -R "$tmp/skills/moodle-phpunit-testing" ~/.cursor/skills/moodle-phpunit-testing &&
rm -rf "$tmp"
```

For one project only, put the folder in `.cursor/skills/moodle-phpunit-testing` 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/SaadRahman01/claude-moodle-dev.git --path skills/moodle-phpunit-testing
```

Or copy the folder to `~/.gemini/skills/moodle-phpunit-testing` yourself.

### VS Code

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

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/SaadRahman01/claude-moodle-dev.git "$tmp" &&
mkdir -p ~/.copilot/skills &&
rm -rf ~/.copilot/skills/moodle-phpunit-testing &&
cp -R "$tmp/skills/moodle-phpunit-testing" ~/.copilot/skills/moodle-phpunit-testing &&
rm -rf "$tmp"
```

For one project only, put the folder in `.github/skills/moodle-phpunit-testing` inside it instead.

### Other agents

Get the folder:

```sh
git clone --depth 1 https://github.com/SaadRahman01/claude-moodle-dev.git
```

Then copy `claude-moodle-dev/skills/moodle-phpunit-testing` into your agent's skills folder as `moodle-phpunit-testing`. Agents that support SKILL.md read one folder per skill.

## FAQ

### What does Moodle phpunit testing need to be useful?

It assumes a Moodle codebase with the PHPUnit tool initialised via admin/tool/phpunit/cli/init.php and a separate test database configured in config.php.

### Does Moodle phpunit testing cover Behat acceptance tests?

No. The skill says to use a separate moodle-behat-testing skill for Behat acceptance tests.

### Does Moodle phpunit testing modify phpunit.xml?

It advises against hand-editing phpunit.xml and says it is regenerated by the init script.

### How do I install Moodle phpunit testing in Claude Code?

Copy the skill folder from GitHub to ~/.claude/skills/moodle-phpunit-testing to use it in all your projects, or to .claude/skills/moodle-phpunit-testing in one project. Or install the moodle-dev plugin, which includes it: /plugin marketplace add SaadRahman01/claude-moodle-dev, then /plugin install moodle-dev@moodle-dev.

### Does Moodle phpunit testing run scripts?

No. It is instructions only, with no 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 Moodle phpunit testing?

Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose. Each reads skills in the SKILL.md format from its own folder; the install steps on this page list them.

### What are the best alternatives to Moodle phpunit testing?

The closest alternatives to Moodle phpunit testing are Moodle behat testing, Moodle plugin development, Phpunit skill, Moodle performance and Moodle web services.

## Where this comes from

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

## Alternatives

- [Moodle behat testing](https://ai-powered.com/skills/moodle-behat-testing): Moodle behat testing is an open-source agent skill for developer tools.
- [Moodle plugin development](https://ai-powered.com/skills/moodle-plugin-development): Moodle plugin development is an open-source agent skill for developer tools.
- [Phpunit skill](https://ai-powered.com/skills/phpunit-skill): Phpunit skill is an open-source agent skill for developer tools.
- [Moodle performance](https://ai-powered.com/skills/moodle-performance): Moodle performance is an open-source agent skill for developer tools.
- [Moodle web services](https://ai-powered.com/skills/moodle-web-services): Moodle web services is an open-source agent skill for developer tools.
- [Moodle upgrade migration](https://ai-powered.com/skills/moodle-upgrade-migration): Moodle upgrade migration is an open-source agent skill for developer tools.
- [Moodle security audit](https://ai-powered.com/skills/moodle-security-audit): Moodle security audit is an open-source agent skill for security.
- [Moodle hooks API](https://ai-powered.com/skills/moodle-hooks-api): Moodle hooks API is an open-source agent skill for developer tools.

---
Source: https://ai-powered.com/skills/moodle-phpunit-testing
