From zenbu-powers
WordPress plugin integration testing complete technical reference. Covers PHPUnit 9 + wp-env + WP_UnitTestCase setup, configuration templates, test patterns, factory methods, and CI workflow. Use this skill whenever the user's task involves writing WordPress plugin tests, setting up PHPUnit for WordPress, configuring wp-env, creating integration tests, testing WP hooks/filters/REST API/shortcodes/post types/user capabilities, or setting up GitHub Actions CI for WordPress plugins. Also use when code involves WP_UnitTestCase, phpunit.xml.dist for WordPress, tests/bootstrap.php, wp scaffold plugin-tests, wp-phpunit, yoast/phpunit-polyfills, yoast/wp-test-utils, or any PHPUnit test extending WP_UnitTestCase. This skill replaces the need to search the web for WordPress testing documentation.
npx claudepluginhub zenbuapps/zenbu-powers --plugin zenbu-powersThis skill uses the workspace's default tool permissions.
> **PHP 8.1** | **PHPUnit ^9.6** | **wp-env (Docker)** | **WP_UnitTestCase**
Guides WordPress testing strategy using PHPUnit and WP_UnitTestCase, with test categories, coverage targets, and AAA patterns. Use for writing tests, infrastructure setup, or coverage review.
Develops WordPress plugins with structure patterns, hooks, security (nonces, sanitization, prepared $wpdb queries), REST API, custom post types, and Settings API.
Supports complete WordPress development workflow: theme and plugin creation, WooCommerce integration, performance optimization, security hardening, and WP 7.0 features like Real-Time Collaboration, AI Connectors. Use for production sites.
Share bugs, ideas, or general feedback.
PHP 8.1 | PHPUnit ^9.6 | wp-env (Docker) | WP_UnitTestCase
| Layer | Tool | Purpose | When |
|---|---|---|---|
| Static Analysis | PHPStan | Type safety, logic consistency | Every commit |
| Integration Test | PHPUnit + wp-env | WP hooks, DB, API logic | Local dev / CI |
| E2E Test | Playwright | Critical UI flows only | CI only |
composer require --dev \
phpunit/phpunit:^9.6 \
yoast/phpunit-polyfills:^1.0 \
wp-phpunit/wp-phpunit:^6.3 \
yoast/wp-test-utils:^1.0
npm install --save-dev @wordpress/env
Why PHPUnit 9, not 10? yoast/phpunit-polyfills on PHP 8.1 falls back to PHPUnit 9. The entire WP ecosystem on PHP 8.1 runs PHPUnit 9 — using ^9.6 is the stable choice.
my-plugin/
├── .wp-env.json
├── composer.json
├── package.json
├── phpunit.xml.dist
├── src/
├── my-plugin.php
└── tests/
├── bootstrap.php
└── integration/
└── ExampleTest.php
Full config file templates: see
references/setup-guide.md
| Method | Purpose |
|---|---|
$this->factory()->post->create( $args ) | Create test post |
$this->factory()->user->create( $args ) | Create test user |
$this->factory()->term->create( $args ) | Create test term |
$this->factory()->comment->create( $args ) | Create test comment |
$this->factory()->attachment->create( $args ) | Create test attachment |
$this->factory()->post->create_many( $count, $args ) | Create N posts |
// Check action registered
$this->assertNotFalse( has_action( 'init', 'my_callback' ) );
// Check filter registered
$this->assertNotFalse( has_filter( 'the_content', 'my_filter' ) );
// Check action fired
$this->assertGreaterThan( 0, did_action( 'my_custom_action' ) );
// Test filter output
$result = apply_filters( 'my_filter', 'input_value' );
$this->assertSame( 'expected_output', $result );
$request = new WP_REST_Request( 'GET', '/my-plugin/v1/items' );
$response = rest_do_request( $request );
$this->assertSame( 200, $response->get_status() );
$this->assertIsArray( $response->get_data() );
$post_id = $this->factory()->post->create();
update_post_meta( $post_id, '_my_key', 'test_value' );
$value = get_post_meta( $post_id, '_my_key', true );
$this->assertSame( 'test_value', $value );
$user_id = $this->factory()->user->create( [ 'role' => 'editor' ] );
wp_set_current_user( $user_id );
$this->assertTrue( current_user_can( 'edit_posts' ) );
$this->assertFalse( current_user_can( 'manage_options' ) );
$output = do_shortcode( '[my_shortcode]' );
$this->assertStringContainsString( '<div', $output );
$this->assertStringNotContainsString( '[my_shortcode]', $output );
npx wp-env start # Start Docker environment
npx wp-env stop # Stop environment
npx wp-env run cli --env-cwd=wp-content/plugins/my-plugin \
vendor/bin/phpunit # Run all tests
npx wp-env run cli --env-cwd=wp-content/plugins/my-plugin \
vendor/bin/phpunit --filter=Test # Run filtered tests
WP_UnitTestCase rolls back DB transactions after each test — no manual cleanup neededconvertErrorsToExceptions, convertNoticesToExceptions, convertWarningsToExceptions (removed in PHPUnit 10)--env-cwd=wp-content/plugins/my-plugin must match the actual plugin directory name inside the containerwp scaffold plugin-tests and bash bin/install-wp-tests.sh before first test run| Need | File |
|---|---|
| Full config file templates (.wp-env.json, phpunit.xml.dist, bootstrap.php) | references/setup-guide.md |
| All test patterns with complete examples | references/test-patterns.md |
| wp-env commands, package.json scripts, GitHub Actions CI YAML | references/ci-workflow.md |