Skip to content

Commit 9e29f99

Browse files
bgrgicakclaude
andauthored
[DOCS] Running PHPUnit tests using the Playground CLI (#3487)
## Motivation for the change, related issues The Playground CLI's `php` subcommand makes it easy to run PHPUnit for plugins and themes without a local database, but there's no guide documenting this workflow. ## Implementation details - Adds a new guide at `packages/docs/site/docs/main/guides/phpunit-testing.md` covering: - Basic usage with `npx @wp-playground/cli@latest php` - Examples for both plugins and themes - Choosing PHP and WordPress versions - Adds the guide to the sidebar in `sidebars.js` (between the programmatic CLI guide and the E2E testing guide) - Adds a link to the guide in the guides index page ## Testing Instructions 1. Run `npm run dev:docs` 2. Navigate to the Guides section 3. Confirm the "Running PHPUnit with the Playground CLI" guide appears in the sidebar and index 4. Open the guide and verify all links work 5. Review the guide content and test it --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent fb6e1e4 commit 9e29f99

3 files changed

Lines changed: 72 additions & 0 deletions

File tree

packages/docs/site/docs/main/guides/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ Automate WordPress Playground workflows with Claude Code. Learn how to install t
4545

4646
Learn how to use the `runCLI` function to control WordPress Playground programmatically from JavaScript/TypeScript for automation, end-to-end testing, and CI/CD pipelines.
4747

48+
## [Running PHPUnit with the Playground CLI](/guides/phpunit-testing)
49+
50+
Run PHPUnit tests for WordPress plugins and themes using the Playground CLI — no database required, clean environment on every run.
51+
4852
## [E2E Testing with Playwright and WordPress Playground](/guides/e2e-testing-with-playwright)
4953

5054
Set up automated end-to-end tests for your WordPress plugins and themes using Playwright and the WordPress Playground CLI.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
title: Running PHPUnit with the Playground CLI
3+
slug: /guides/phpunit-testing
4+
description: Run PHPUnit tests for WordPress plugins and themes using the Playground CLI — no database required, clean environment on every run.
5+
sidebar_class_name: navbar-build-item
6+
---
7+
8+
The [Playground CLI](/developers/local-development/wp-playground-cli) includes a `php` subcommand that runs PHP scripts directly inside the Playground environment. By mounting your plugin or theme into the Playground filesystem, you can run PHPUnit without a local database. Every run starts with a clean WordPress installation, so tests are fully isolated.
9+
10+
:::info
11+
This guide assumes your plugin or theme has PHPUnit installed via Composer (`composer require --dev phpunit/phpunit`). The `vendor/bin/phpunit` path used below assumes a standard Composer setup.
12+
:::
13+
14+
## Running tests
15+
16+
From your plugin or theme directory, run the following command. Replace `themes/THEME_NAME` with the path to your plugin or theme:
17+
18+
```bash
19+
npx @wp-playground/cli@latest php \
20+
--auto-mount \
21+
-- \
22+
/wordpress/wp-content/themes/THEME_NAME/vendor/bin/phpunit \
23+
-c /wordpress/wp-content/themes/THEME_NAME/phpunit.xml.dist
24+
```
25+
26+
The `--auto-mount` flag detects whether the current directory is a plugin, theme, or WordPress installation and mounts it at the correct path under `/wordpress/wp-content/`. The `--` separates CLI flags from arguments passed to the PHP interpreter, and you can pass any arguments supported by your PHPUnit configuration.
27+
28+
For a plugin, the path would use `plugins/` instead:
29+
30+
```bash
31+
npx @wp-playground/cli@latest php \
32+
--auto-mount \
33+
-- \
34+
/wordpress/wp-content/plugins/MY_PLUGIN/vendor/bin/phpunit \
35+
-c /wordpress/wp-content/plugins/MY_PLUGIN/phpunit.xml.dist
36+
```
37+
38+
You can also use `--mount` to explicitly map a local directory to a path inside the Playground filesystem:
39+
40+
```bash
41+
npx @wp-playground/cli@latest php \
42+
--mount=.:/wordpress/wp-content/plugins/MY_PLUGIN \
43+
-- \
44+
/wordpress/wp-content/plugins/MY_PLUGIN/vendor/bin/phpunit \
45+
-c /wordpress/wp-content/plugins/MY_PLUGIN/phpunit.xml.dist
46+
```
47+
48+
## Choosing PHP and WordPress versions
49+
50+
Use the `--php` and `--wp` flags to test against specific versions:
51+
52+
```bash
53+
npx @wp-playground/cli@latest php \
54+
--auto-mount \
55+
--php=8.1 \
56+
--wp=6.5 \
57+
-- \
58+
/wordpress/wp-content/plugins/MY_PLUGIN/vendor/bin/phpunit \
59+
-c /wordpress/wp-content/plugins/MY_PLUGIN/phpunit.xml.dist
60+
```
61+
62+
Supported PHP versions range from 7.4 to 8.5. For WordPress, you can use a specific version number, `latest`, `nightly`, or `beta`.
63+
64+
## Next steps
65+
66+
- [Playground CLI documentation](/developers/local-development/wp-playground-cli) — full CLI reference and configuration options
67+
- [E2E Testing with Playwright](/guides/e2e-testing-with-playwright) — browser-based end-to-end testing for WordPress plugins and themes

packages/docs/site/sidebars.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const sidebars = {
5353
'main/guides/github-action-pr-preview',
5454
'main/guides/playground-for-everyone',
5555
'main/guides/programmatic-playground-cli',
56+
'main/guides/phpunit-testing',
5657
'main/guides/e2e-testing-with-playwright',
5758
],
5859
},

0 commit comments

Comments
 (0)