Download the PHP package makeweb/wordpress-test-environment without Composer
On this page you can find all versions of the php package makeweb/wordpress-test-environment. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download makeweb/wordpress-test-environment
More information about makeweb/wordpress-test-environment
Files in makeweb/wordpress-test-environment
Package wordpress-test-environment
Short Description Boot wordpress to test your code in an actual wordpress environment
License MIT
Informations about the package wordpress-test-environment
Wordpress Test Environment
Easily pull Wordpress in to your plugin, library or package as a composer development dependency and test your code in an actual wordpress environment.
This package aims to support developers who wish to test code which depends on Wordpress in two key ways:
1) Boot wordpress to allow usage of wordpress database and global functions
2) Simulate actual HTTP requests to the wordpress application
Installation
From command line:
composer require --dev makeweb/wordpress-test-environment
Basic Usage
1) Once installed, Create a new database in your local MySQL installation.
2) Create a .env
file in the base directory of the codebase you are testing and add the following to it (updating the credentials to match your newly created database and local environment):
3) Initialise Wordpress in your parent test case class
Pass the relative path to the directory which contains your .env file into loadEnvFrom()
4) Usage in your tests
Boot only
If you simply wish to boot wordpress to allow access to the database and Wordpress global functions. Add the following lines to the start of your test.
In your test file
In your main plugin file or source code
Here we are just calling a native Wordpress function get_site_url()
. If everything is set up correctly the test above will
pass with the code below because get_site_url()
has been defined by wordpress.
Note: Make sure you are including the plugin file in your test bootstrap file manually or with an autoloader like composer
Test HTTP requests to your wordpress application
Sometimes your theme, plugin or library might actually handle HTTP requests (for example, if you are creating an API), or
perhaps you just want to test the way your code affects the actual html output of the application. The Wordpress
class
exposes a get method which simulates an actual HTTP GET request to the given url. Wordpress, and your dependent code
will be booted and executed as it would be in production. We don't need to call $this->wordpress->boot()
when using the HTTP
methods because it is done for us automatically.
In your test file
In your plugin file or source code
All versions of wordpress-test-environment with dependencies
vlucas/phpdotenv Version ^2.4
illuminate/support Version ^5.6