|
1 | | -# wpunit-helpers |
| 1 | +# WPUnit Helpers |
| 2 | +[](https://github.com/pantheon-systems/wpunit-helpers/actions/workflows/lint.yml)   [](https://docs.pantheon.io/oss-support-levels#unofficial-support) |
| 3 | + |
2 | 4 | Unified scripts for installing and running automated WP Unit Tests. |
| 5 | + |
| 6 | +## What is this? |
| 7 | + |
| 8 | +This is a set of scripts that can be used in a WordPress plugin or theme repository to run automated tests using the WP Unit Test Framework built on top of PHPUnit. The Composer plugin will install these scripts into the dependent project's `bin` directory, allowing you to add helper scripts to your `composer.json`. |
| 9 | + |
| 10 | +## What's included? |
| 11 | + |
| 12 | +* `install-wp-tests.sh` - The _de facto_ standard script for installing the WP Unit Test Framework. |
| 13 | +* `install-local-tests.sh` - A helper script for installing WP Unit Tests locally. See [Local Testing](#local-testing) for more information. |
| 14 | +* `phpunit-test.sh` - A helper script for running WP Unit Tests that is intended for use in CI. |
| 15 | + |
| 16 | +## Installation |
| 17 | + |
| 18 | +Use Composer to install this package as a development dependency: |
| 19 | + |
| 20 | +```bash |
| 21 | +composer require --dev pantheon-systems/wpunit-helpers |
| 22 | +``` |
| 23 | + |
| 24 | +On installation, the Composer plugin will copy the scripts into the `bin` directory of the dependent project. You can then add the scripts to your `composer.json`: |
| 25 | + |
| 26 | +```json |
| 27 | +{ |
| 28 | + "scripts": { |
| 29 | + "phpunit": "phpunit --do-not-cache-result", |
| 30 | + "test": "@phpunit", |
| 31 | + "test:install": "bin/install-local-tests.sh --no-db", |
| 32 | + "test:install:withdb": "bin/install-local-tests.sh" |
| 33 | + } |
| 34 | +} |
| 35 | +``` |
| 36 | + |
| 37 | +## Local Testing |
| 38 | +The `install-local-tests.sh` script is highly configurable to allow for a variety of local environment setups. Any parameter that could be passed into `install-wp-tests.sh` is set up as an optional flag in `install-local-tests.sh`. By default, the script with no flags will assume that a new database should be created as `root` with no password. |
| 39 | + |
| 40 | +### Flags |
| 41 | + |
| 42 | +#### `--no-db` |
| 43 | +This flag will skip the database creation step. This is useful if you are using a local database that is already set up. |
| 44 | + |
| 45 | +#### `--dbname` |
| 46 | +This flag will set the name of the database to be created. The default value is `wordpress_test`. |
| 47 | + |
| 48 | +#### `--dbuser` |
| 49 | +This flag will set the username of the database user to be created. The default value is `root`. |
| 50 | + |
| 51 | +#### `--dbpass` |
| 52 | +This flag will set the password of the database user to be created. The default value is an empty string. |
| 53 | + |
| 54 | +#### `--dbhost` |
| 55 | +This flag will set the host of the database to be created. The default value is `127.0.0.1`. |
| 56 | + |
| 57 | +#### `--wpversion` |
| 58 | +This flag will set the version of WordPress to be installed. The default value is `latest`. Using `nightly` here will use the latest nightly build of WordPress. |
0 commit comments