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.
Short Description WorDBless allows you to use WordPress core functions in your PHPUnit tests without having to set up a database and the whole WordPress environment
All versions of wordbless with dependencies
Informations about the package 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
Make sure to copy db.php
Add this script to your
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!
BaseTestCase in order to have all the setup and teardown in place.
Note WorDBless uses
@after annotations rather than overriding PHPUnit's
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
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?
Manipulating options will work.
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:
- 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
You can create, edit and delete users.
Here is a non-exaustive list of functions supported:
new WP_User( $id )to fetch a user
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
Populating default options
By default, only
home options are populated with
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.
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.