PHPackages                             automattic/wordbless - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. automattic/wordbless

ActiveWordpress-dropin[Testing &amp; Quality](/categories/testing)

automattic/wordbless
====================

WorDBless allows you to use WordPress core functions in your PHPUnit tests without having to set up a database and the whole WordPress environment

0.6.0(1y ago)1457.0M—2.4%9[3 issues](https://github.com/Automattic/wordbless/issues)[1 PRs](https://github.com/Automattic/wordbless/pulls)20GPL-2.0-or-laterPHPPHP &gt;=7.2.24CI passing

Since Aug 17Pushed 2mo ago11 watchersCompare

[ Source](https://github.com/Automattic/wordbless)[ Packagist](https://packagist.org/packages/automattic/wordbless)[ RSS](/packages/automattic-wordbless/feed)WikiDiscussions trunk Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (17)Used By (20)

WorDBless
=========

[](#wordbless)

[![CI](https://github.com/Automattic/wordbless/workflows/CI/badge.svg)](https://github.com/Automattic/wordbless/actions?query=workflow%3ACI)

WorDBless allows you to use WordPress core functions in your PHPUnit tests without having to set up a database and the whole WordPress environment

Usage
-----

[](#usage)

### Require WorDBless

[](#require-wordbless)

```
composer require --dev automattic/wordbless
```

### Make sure to copy db.php

[](#make-sure-to-copy-dbphp)

Add this script to your `composer.json`:

```
	"scripts": {
		"post-install-cmd": "WorDBless\\Composer\\InstallDropin::copy",
		"post-update-cmd": "WorDBless\\Composer\\InstallDropin::copy"
	},
```

Alternatively, you can manually copy `src/dbless-wpdb.php` to the `wordpress` folder created in your project under `wp-content/db.php`.

### Initialize it in your bootstrap file

[](#initialize-it-in-your-bootstrap-file)

In your PHP Unit bootstrap file add:

```
require_once __DIR__ . '/../vendor/autoload.php'; // adjust the path as needed

\WorDBless\Load::load();
```

That's it! You can now use WordPress core functions in your tests!

### Writing tests

[](#writing-tests)

Extend the `BaseTestCase` in order to have all the setup and teardown in place.

```
class My_Tests extends \WorDBless\BaseTestCase {

	public function test_add() {
		add_option( 'test', 123 );
		$this->assertEquals( 123, get_option( 'test' ) );
	}

}
```

Note WorDBless uses `@before` and `@after` annotations rather than overriding PHPUnit's `setUp` and `tearDown` methods.

If you choose not to extend this base class, no problem. Just remember that WorDBless won't be set up or torn down for you. Check BaseTestCase::set\_up\_wordbless() and BaseTestCase::teardown\_wordbless() to see how to do it for yourself.

What will work and what will not work?
--------------------------------------

[](#what-will-work-and-what-will-not-work)

Disclaimer: This is still experimental, so all testing is very welcome.

Basically any WordPress core function will work. Things like `wp_parse_args`, `add_query_arg`, etc.

Hooks and filters will work.

Most of the things that uses the database WILL NOT work, unless you believe in magic.

### What magic WorDBless adds?

[](#what-magic-wordbless-adds)

#### Options

[](#options)

Manipulating options will work. `get_option`, `update_option`, `add_option` and `delete_option` should work fine!

#### Posts and Post meta

[](#posts-and-post-meta)

Manipulating (creating, updating, deleting) posts and attachments will work. Fetching a single post will also work. Here is a non-exaustive list of functions supported:

- `wp_insert_post`
- `wp_update_post`
- `wp_delete_post`
- `wp_trash_post`
- `wp_untrash_post`
- `get_post`
- `get_post_meta`
- `add_post_meta`
- `update_post_meta`
- `delete_post_meta`
- `get_metadata_by_mid`
- `update_metadata_by_mid`
- `delete_metadata_by_mid`
- `wp_insert_attachment`
- `wp_get_attachment_image`
- and almost anything related to the manipulation of one attachment

Note: Fetching posts using `WP_Query` will not work (yet)! To fetch a post, use `get_post( $id )`.

#### Users and capabilities

[](#users-and-capabilities)

You can create, edit and delete users.

Here is a non-exaustive list of functions supported:

- `wp_insert_user`
- `wp_update_user`
- `wp_delete_user`
- `get_userdata`
- `new WP_User( $id )` to fetch a user
- `user_can`
- `current_user_can`
- `set_current_user`
- `get_current_user_id`
- `wp_get_current_user`
- `get_user_meta`
- `update_user_meta`
- `add_user_meta`
- `delete_user_meta`

Posts can be assigned to users and proper capabilities will be correctly checked. When deleting a user, reassigning posts to other user will also work.

Note: Fetching users using `WP_Users_Query` will not work! To fetch a user, use `get_userdata()`, `get_user_by` or `WP_User` class.

### Populating default options

[](#populating-default-options)

By default, only `siteurl` and `home` options are populated with `http://example.org`.

If you want, you can add more options to be loaded by default.

Just declare a `dbless_default_options()` function in your bootstrap and make it return an array where the keys are option names and values, options values.

Examples
--------

[](#examples)

Here's a simple example, using only few WordPress functions:

[Jetpack Admin UI package](https://github.com/Automattic/jetpack/blob/master/projects/packages/admin-ui/tests/php)

And here a more complex example, using WorDBless to test REST endpoints, create users and play with hooks:

[Jetpack Backup package](https://github.com/Automattic/jetpack/blob/master/projects/packages/backup/tests/php)

Running our CI locally
----------------------

[](#running-our-ci-locally)

First [install phive](https://phar.io/#Install) globally on your computer.

Then issue the following single command.

```
composer run-script ci
```

###  Health Score

55

—

FairBetter than 98% of packages

Maintenance68

Regular maintenance activity

Popularity59

Moderate usage in the ecosystem

Community38

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~152 days

Recently: every ~17 days

Total

12

Last Release

391d ago

PHP version history (2 changes)0.1.0PHP &gt;=5.6.20

0.5.0PHP &gt;=7.2.24

### Community

Maintainers

![](https://www.gravatar.com/avatar/7c5869ecbb8e0eac7e8b8e0f3cf7bdd8d5fcdc4abc10a72281872c53f8639d44?d=identicon)[automattic](/maintainers/automattic)

![](https://www.gravatar.com/avatar/11609890f6e7a840715f4cfc9622d77ea64b7dfc024df5643fbf8471a18c00f3?d=identicon)[kraft](/maintainers/kraft)

![](https://www.gravatar.com/avatar/5326730499ec14e274f51b9bcc39db6aac0fb38b33849715aae0e2587a2b93df?d=identicon)[jeherve](/maintainers/jeherve)

![](https://www.gravatar.com/avatar/6e220e167e341c28b1aa10bf0bb0374999068329f8683d3187ee3cf6749b8837?d=identicon)[dereksmart](/maintainers/dereksmart)

![](https://www.gravatar.com/avatar/d9dcd98edfbe31a7fa391458eda78cc74ec6b899c49bb687be90b79ba1f69def?d=identicon)[leogermani](/maintainers/leogermani)

---

Top Contributors

[![leogermani](https://avatars.githubusercontent.com/u/971483?v=4)](https://github.com/leogermani "leogermani (27 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (23 commits)")[![kraftbj](https://avatars.githubusercontent.com/u/88897?v=4)](https://github.com/kraftbj "kraftbj (13 commits)")[![anomiex](https://avatars.githubusercontent.com/u/1030580?v=4)](https://github.com/anomiex "anomiex (5 commits)")[![jeherve](https://avatars.githubusercontent.com/u/426388?v=4)](https://github.com/jeherve "jeherve (3 commits)")[![kbrown9](https://avatars.githubusercontent.com/u/50059399?v=4)](https://github.com/kbrown9 "kbrown9 (2 commits)")[![heiglandreas](https://avatars.githubusercontent.com/u/91998?v=4)](https://github.com/heiglandreas "heiglandreas (1 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![manzoorwanijk](https://avatars.githubusercontent.com/u/18226415?v=4)](https://github.com/manzoorwanijk "manzoorwanijk (1 commits)")[![nateweller](https://avatars.githubusercontent.com/u/10933065?v=4)](https://github.com/nateweller "nateweller (1 commits)")[![cezarpopa](https://avatars.githubusercontent.com/u/3178790?v=4)](https://github.com/cezarpopa "cezarpopa (1 commits)")[![wppunk](https://avatars.githubusercontent.com/u/19273242?v=4)](https://github.com/wppunk "wppunk (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/automattic-wordbless/health.svg)

```
[![Health](https://phpackages.com/badges/automattic-wordbless/health.svg)](https://phpackages.com/packages/automattic-wordbless)
```

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[beberlei/assert

Thin assertion library for input validation in business models.

2.4k96.9M570](/packages/beberlei-assert)[mikey179/vfsstream

Virtual file system to mock the real file system in unit tests.

1.4k108.0M2.7k](/packages/mikey179-vfsstream)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)[phpspec/phpspec

Specification-oriented BDD framework for PHP 7.1+

1.9k36.7M3.1k](/packages/phpspec-phpspec)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
