Download the PHP package idearia/wp-tests without Composer
On this page you can find all versions of the php package idearia/wp-tests. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download idearia/wp-tests
More information about idearia/wp-tests
Files in idearia/wp-tests
Package wp-tests
Short Description A simple class to run PHPUnit tests in WordPress.
License GPL-3.0-or-later
Homepage https://github.com/Idearia/wp-tests
Informations about the package wp-tests
Defines the class WordPressTestCase
to run PHPUnit tests in a WordPress installation, with support for logging and multisite.
Usage
- Install with
composer require idearia/wp-tests --dev
. - Create a test case by extending
Idearia\WpTests\WordPressTestCase
. - When you run the test, WordPress will be automatically loaded.
Have a look in the the example folder. You'll find:
- an example test that creates, fetches and deletes a WordPress post;
- an example phpunit.xml file with the available options.
Logging support
- To log a message to screen, call
self::print( $message )
. - To log a message to file, call
self::log( $message )
. - The file will be named after the test class and placed in the subfolder tests/logs.
- The log file will reset at each run unless you set
protected static $deleteLogFile = false;
in your test case. - Customize the log folder via the
logsPath
environment variable. - For further customizations, please refer to the documentation of the Loggable trait.
Multisite support
By default, the tests will be run on the main blog.
To run the tests on a different blog, add the siteUrl
environment variable to your phpunit.xml file:
Then, you are free to set siteUrl
the way you see fit:
- In a dotenv file.
- When you run phpunit:
siteUrl=http://example.com/blog phpunit
. - At the shell level:
export siteUrl=http://example.com/blog
. - In your test case setup:
putenv( 'siteUrl=http://example.com/blog' );
. - Hard-code it in phpunit.xml.
Custom WordPress path
If your WordPress installation is non-standard, you can specify a custom WordPress path by setting the wordPressPath
environment variable.
You can use both relative and absolute paths.
To set wordPressPath
in phpunit.xml: