Skip to content
Composer package providing PHPUnit test utilities and bootstrap helpers for WordPress plugin and theme test suites — rep...

2023 · Creator & Maintainer

PHPUnit WordPress Tests

Composer package providing PHPUnit test utilities and bootstrap helpers for WordPress plugin and theme test suites — replaces the WordPress test-suite bootstrap boilerplate.

The challenge

Bootstrapping a PHPUnit suite for a WordPress plugin means copy-pasting 100+ lines of test bootstrap boilerplate, loading WP, faking HTTP, and stubbing globals. Every new repo reinvents it.

The result

A composer package providing the bootstrap helpers, factories, and HTTP mocks as a dependency — `composer require`, point phpunit at it, write tests.

Year
2023
Role
Creator & Maintainer
Stack
4 teches
Status
Published

Overview

Setting up a proper PHPUnit test suite for a WordPress plugin involves a lot of boilerplate: bootstrap files, database setup, factory helpers, and WP_Mock configuration. This package extracts that boilerplate into a reusable Composer dependency.

What It Provides

  • Drop-in bootstrap that loads WordPress test environment
  • Pre-configured WP factories (posts, users, terms, meta)
  • Custom assertion helpers: assertPostExists(), assertOptionEquals(), assertHookFired()
  • Test case base class with before/after cleanup
  • Compatible with WordPress 6.x and PHP 8.x

Usage

BASH
composer require --dev mralaminahamed/phpunit-wordpress-tests

Configure in phpunit.xml:

XML
<phpunit bootstrap="vendor/mralaminahamed/phpunit-wordpress-tests/bootstrap.php">

Adoption

Over 900 Composer installs across WordPress plugin repositories.

Tech

PHP, PHPUnit, WordPress test environment, WP_Mock.

Share
𝕏 in

Related work

Building something similar?

Let's talk about your project.

Open to freelance engagements and consulting on Laravel, WordPress, and AI-powered systems.