Download the PHP package automattic/wordbless without Composer

On this page you can find all versions of the php package automattic/wordbless. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

Please rate this library. Is it a good library?

All versions of wordbless with dependencies

Informations about the package wordbless

WorDBless

CI

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

Require WorDBless

Make sure to copy db.php

Add this script to your composer.json:

Alternatively, you can manually copy the file.

Initialize it in your bootstrap file

In your PHP Unit bootstrap file add:

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

Writing tests

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

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?

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?

Options

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

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:

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

Users and capabilities

You can create, edit and delete users.

Here is a non-exaustive list of functions supported:

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

By default, only site_url 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.

Example

See a live example here -> https://github.com/Automattic/jetpack/pull/16163

Running our CI locally

First install phive globally on your computer.

Then issue the following single command.


Version
Requires php Version >=5.6.20
roots/wordpress Version ^5.4

The package automattic/wordbless contains the following files

Loading the files please wait ....