PHPackages                             wpsyntex/wp-phpunit - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. wpsyntex/wp-phpunit

ActiveLibrary[Testing &amp; Quality](/categories/testing)

wpsyntex/wp-phpunit
===================

PHPUnit library for WordPress

060.0k↑109.7%1PHP

Since Dec 14Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/polylang/wp-phpunit)[ Packagist](https://packagist.org/packages/wpsyntex/wp-phpunit)[ RSS](/packages/wpsyntex-wp-phpunit/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (3)Used By (1)

Polylang PHPUnit
================

[](#polylang-phpunit)

A code library for WP Syntex projects, containing:

- scripts to install the WordPress test suite,
- scripts to install the required plugins and themes,
- scripts for building and distributing the project,
- bootstraps allowing to init unit and integration tests,
- helpers for the tests.

How to
------

[](#how-to)

### Install the test suite

[](#install-the-test-suite)

The test suite is installed in **your project**'s `tmp` folder.

To tell the installation script how to connect to your database, you can create a `DB-CONFIG` file at the root of your project and formatted like follow (the file is not versioned with git of course).
Each line is optional, the default values are:

```
db_host: localhost
db_name: wordpress_tests
db_user: root
db_pass: '' (an empty string)
```

### Install the dependencies

[](#install-the-dependencies)

The plugins and themes are installed in **your project**'s `tmp` folder.

Create a `install-plugins.sh` file that launches all the downloads. Example:

```
#!/usr/bin/env bash

. "$PWD/vendor/wpsyntex/wp-phpunit/bin/wp-download-tools.sh"

mkdir -p $WP_PLUGINS_DIR
mkdir -p $WP_THEMES_DIR

# Install WP All Import Pro.
downloadPluginFromEdd wp-all-import-pro 'WP All Import' https://www.wpallimport.com

# Install Polylang Pro.
downloadPolylangPro

# Install Polylang for WooCommerce.
downloadPolylangForWoocommerce

# Install WooCommerce.
downloadWoocommerce

# Install TwentyFourteen.
downloadThemeFromRepository twentyfourteen
```

Note: two variables are available for you to use: `$WP_PLUGINS_DIR` and `$WP_THEMES_DIR`. They contain the path to `tmp/plugins` and `tmp/themes` respectively, where the plugins and themes are installed. Those folders are not created by default so don't forget to do `mkdir -p $WP_PLUGINS_DIR` and/or `mkdir -p $WP_THEMES_DIR` like in the previous example, before using the download functions.

Premium plugins installed from EDD need a bit more attention because they need a license key. You can provide it by creating a `LICENSE-CODES` file at the root of your project and formatted like follow (the file is not versioned with git of course):

```
license {PLUGIN-SLUG}:{YOUR-LICENSE}
site {PLUGIN-SLUG}:{YOUR-SITE}
```

Depending on EDD config, the `site` line may not be required.
Also, if your plugin from EDD doesn't require a license key, do the following:

```
license {PLUGIN-SLUG}:none
```

### Composer scripts

[](#composer-scripts)

Then you can create composer scripts like these ones for example:

```
{
    "scripts": {
        "install-suite": "vendor/wpsyntex/wp-phpunit/bin/install-wp-suite.sh",
        "install-suite-with-db": "vendor/wpsyntex/wp-phpunit/bin/install-wp-suite.sh latest true",
        "install-plugins": "Tests/bin/install-plugins.sh",
        "install-tests": [
            "@install-suite",
            "@install-plugins"
        ],
        "install-tests-with-db": [
            "@install-suite-with-db",
            "@install-plugins"
        ],
        "build": "vendor/wpsyntex/wp-phpunit/bin/build.sh",
        "build-update": "vendor/wpsyntex/wp-phpunit/bin/build.sh -- -u",
        "dist": "vendor/wpsyntex/wp-phpunit/bin/distribute.sh -- polylang-foobar"
    },
    "scripts-descriptions": {
        "install-suite": "Installs the WordPress tests suite (without installing the database).",
        "install-suite-with-db": "Installs the WordPress tests suite (with database creation).",
        "install-plugins": "Installs dependencies needed for integration tests.",
        "install-tests": "Installs both the WordPress tests suite (without installing the database) and the dependencies needed for integration tests.",
        "install-tests-with-db": "Installs both the WordPress tests suite (with database creation) and the dependencies needed for integration tests, without creating the database.",
        "build": "Builds the project.",
        "build-update": "Builds the project (runs `composer update` instead of `composer install`).",
        "dist": "Makes the zip file to distribute the project release."
    }
}
```

### Integration tests

[](#integration-tests)

#### Bootstrap for integration tests

[](#bootstrap-for-integration-tests)

Example for your `bootstrap.php` file:

```
