Download the PHP package alvarodelera/pest-wp-plugin without Composer
On this page you can find all versions of the php package alvarodelera/pest-wp-plugin. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alvarodelera/pest-wp-plugin
More information about alvarodelera/pest-wp-plugin
Files in alvarodelera/pest-wp-plugin
Package pest-wp-plugin
Short Description Pest plugin for WordPress testing with SQLite support and zero-config setup
License MIT
Homepage https://github.com/alvarodelera/pest-wp-plugin
Informations about the package pest-wp-plugin
PestWP - Pest Plugin for WordPress
A modern testing plugin for WordPress using Pest PHP with SQLite database support and automatic database isolation.
Features
- 🚀 Modern Testing: Built on Pest v5 and PHPUnit 13
- 🗄️ SQLite Integration: Automatic SQLite database setup for fast, isolated tests
- 🔄 Database Isolation: Automatic database state management between tests using SAVEPOINT/ROLLBACK
- 🏭 Type-Safe Factories: Strongly-typed helper functions for creating WordPress objects
- 🔧 Zero Configuration: Automatic WordPress installation and setup
- 💡 IDE Support: Full autocompletion and type checking with PHPStan level 9
Requirements
- PHP 8.4 or higher
- Composer
Installation
Quick Start (< 5 minutes)
Get your first WordPress test running in under 5 minutes:
1. Add PestWP to your project
2. Create your first test
3. Configure Pest
4. Run your tests
That's it! PestWP automatically:
- Downloads WordPress to
.pest/wordpress/ - Sets up SQLite database (no MySQL needed)
- Isolates each test with database snapshots
- Provides type-safe factories and helpers
Testing Your WordPress Plugin
If you're developing a WordPress plugin and want to test it with PestWP, you need to configure Pest to load your plugin when WordPress boots.
Basic Plugin Configuration
Complete Configuration Example
For a full-featured plugin test setup:
Example Plugin Test
Project Structure
Recommended test structure for a WordPress plugin:
Basic Test Example
Integration vs Browser Testing
PestWP supports two types of testing. Choose the right one for your needs:
| Feature | Integration Tests | Browser Tests |
|---|---|---|
| Speed | ⚡ Very fast (~2ms/test) | 🐢 Slower (~500ms/test) |
| Database | SQLite (automatic) | MySQL (requires setup) |
| UI Testing | ❌ No | ✅ Yes (full browser) |
| JavaScript | ❌ No | ✅ Yes |
| Setup | Zero config | Requires WordPress server |
| Best For | Hooks, filters, CRUD, permissions | Admin UI, Gutenberg, forms |
When to Use Integration Tests
Use integration tests for:
- Testing WordPress hooks and filters
- CRUD operations (posts, users, terms, options)
- User permissions and capabilities
- Custom post types and taxonomies
- Database queries and metadata
When to Use Browser Tests
Use browser tests for:
- Admin UI workflows
- Gutenberg editor interactions
- JavaScript functionality
- Form submissions
- Visual regression testing
Type-Safe Factory Helpers
PestWP provides strongly-typed factory functions for creating WordPress objects:
Create Posts
Create Users
Create Terms
Create Attachments
Authentication Helpers
PestWP provides convenient helpers for testing authentication and user permissions:
Login as User
Logout
Check Current User
Testing Different User Roles
Custom WordPress Expectations
PestWP extends Pest's expectation API with WordPress-specific assertions for more readable and expressive tests.
Post Status Expectations
Check post statuses with intuitive methods:
Available status expectations:
toBePublished()- Post is publishedtoBeDraft()- Post is drafttoBePending()- Post is pending reviewtoBePrivate()- Post is privatetoBeInTrash()- Post is in trash
WP_Error Expectations
Test WordPress errors elegantly:
Metadata Expectations
Test post and user metadata:
Hook Expectations
Test action and filter registrations:
Term Expectations
Test taxonomy term assignments:
Chaining Expectations
All custom expectations support chaining:
Database Isolation
Every test automatically runs in an isolated database transaction. Changes are rolled back after each test:
Browser Testing (E2E)
PestWP integrates with Pest Browser Plugin for browser-based end-to-end testing of your WordPress site.
Quick Setup
Features
- 🐘 Native PHP: Write browser tests in PHP, not TypeScript
- ⚡ Pest Integration: Uses the same Pest syntax you already know
- 🎯 Laravel Dusk API: Familiar API if you've used Laravel Dusk
- 📸 Auto Screenshots: Automatic screenshots on test failures
- 🌐 Multi-Browser: Support for Chromium, Firefox, and WebKit
Example Browser Test
Running Browser Tests
Browser Configuration
The getBrowserConfig() helper reads configuration from your tests/Pest.php or environment variables:
Or use environment variables:
WordPress Environment Setup
Browser tests require a running WordPress instance (unlike integration tests which use SQLite). Here are common setups:
Option 1: wp-env (Recommended for WordPress development)
wp-env is the official WordPress local environment tool.
Option 2: Docker Compose
Create a docker-compose.yml for isolated testing:
Option 3: Local by Flywheel / MAMP / XAMPP
If you have a local WordPress installation:
Option 4: wp-browser (Advanced)
For projects already using wp-browser, you can configure PestWP to use the same WordPress instance:
Integration Tests vs Browser Tests: Which WordPress?
| Test Type | WordPress Instance | Database |
|---|---|---|
| Integration | Auto-installed in .pest/wordpress/ |
SQLite (isolated) |
| Browser | Your running server (Docker, wp-env, etc.) | MySQL/MariaDB |
Important: Browser tests interact with a real WordPress installation. Changes made during browser tests persist unless you reset the database manually or use a fresh container.
WP Admin Locators
PestWP provides helper functions for building URLs and CSS selectors for WordPress admin UI elements. These locators are designed to be resilient across WordPress versions (6.5+).
URL Helpers
Gutenberg Selectors
Admin UI Selectors
For complete browser testing documentation, see docs/BROWSER_TESTING.md.
Configuration
The plugin works out of the box, but you can customize it in your tests/Pest.php:
Project Structure
Development
How It Works
- Auto Installation: On first run, PestWP downloads WordPress and SQLite integration plugin
- Bootstrap: Pest automatically loads WordPress with SQLite before running tests
- Isolation: Each test runs with automatic database snapshots (~1.7ms overhead)
- Type Safety: Factory helpers provide full IDE autocompletion and static analysis
Troubleshooting
Common Issues
Tests fail with "WordPress not found"
PHPStan memory errors
Browser tests timeout
Database isolation not working
Debug Mode
Enable verbose output for troubleshooting:
GitHub Actions (CI/CD)
PestWP includes ready-to-use GitHub Actions workflows for continuous integration.
Quick Setup
Copy the simple workflow to your project:
Full Workflow Template
For a complete workflow with code quality checks, matrix testing, and browser tests, copy:
This includes:
- ✅ Matrix testing (PHP 8.4)
- ✅ PHPStan static analysis
- ✅ Code style checks (Pint)
- ✅ WordPress caching for faster builds
- ✅ Coverage reporting (Codecov)
- ✅ Browser tests (on-demand)
Running Browser Tests in CI
Browser tests require a running WordPress instance. The full workflow uses Docker services:
Enable browser tests by including [browser] in your commit message, or run them on a schedule.
Credits
- Built on Pest PHP
- Uses WordPress SQLite Integration
License
MIT License. See LICENSE for details.
All versions of pest-wp-plugin with dependencies
pestphp/pest Version ^5.0
pestphp/pest-plugin Version ^5.0
pestphp/pest-plugin-browser Version ^5.0