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 tearDownin place.

If you choose not to extend this base class, no problem, just make sure to call its setUp and tearDown methods.

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 for posts using WP_Query will not work (yet)! To get a post use get_post( $id ).

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 ....