PHPackages                             wp-cli/wp-cli-tests - 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. wp-cli/wp-cli-tests

ActivePhpcodesniffer-standard[Testing &amp; Quality](/categories/testing)

wp-cli/wp-cli-tests
===================

WP-CLI testing framework

v5.1.10(2w ago)423.0M↑75.5%27[1 issues](https://github.com/wp-cli/wp-cli-tests/issues)[1 PRs](https://github.com/wp-cli/wp-cli-tests/pulls)20MITPHPPHP &gt;=7.2.24CI passing

Since Aug 4Pushed 3w ago5 watchersCompare

[ Source](https://github.com/wp-cli/wp-cli-tests)[ Packagist](https://packagist.org/packages/wp-cli/wp-cli-tests)[ Docs](https://wp-cli.org)[ RSS](/packages/wp-cli-wp-cli-tests/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (10)Dependencies (79)Versions (146)Used By (20)

wp-cli/wp-cli-tests
===================

[](#wp-cliwp-cli-tests)

WP-CLI testing framework

[![Testing](https://github.com/wp-cli/wp-cli-tests/actions/workflows/testing.yml/badge.svg)](https://github.com/wp-cli/wp-cli-tests/actions/workflows/testing.yml)

Quick links: [Using](#using) | [Contributing](#contributing) | [Support](#support)

Using
-----

[](#using)

To make use of the WP-CLI testing framework, you need to complete the following steps from within the package you want to add them to:

1. Add the testing framework as a development requirement:

    ```
    composer require --dev wp-cli/wp-cli-tests
    ```
2. Add the required test scripts to the `composer.json` file:

    ```
    "scripts": {
        "behat": "run-behat-tests",
        "behat-rerun": "rerun-behat-tests",
        "lint": "run-linter-tests",
        "phpcs": "run-phpcs-tests",
        "phpcbf": "run-phpcbf-cleanup",
        "phpunit": "run-php-unit-tests",
        "prepare-tests": "install-package-tests",
        "test": [
            "@lint",
            "@phpcs",
            "@phpunit",
            "@behat"
        ]
    }
    ```

    You can of course remove the ones you don't need.
3. Optionally add a modified process timeout to the `composer.json` file to make sure scripts can run until their work is completed:

    ```
    "config": {
        "process-timeout": 1800
    },
    ```

    The timeout is expressed in seconds.
4. Optionally add a `behat.yml` file to the package root with the following content:

    ```
    default:
      suites:
        default:
          contexts:
            - WP_CLI\Tests\Context\FeatureContext
          paths:
            - features
    ```

    This will make sure that the automated Behat system works across all platforms. This is needed on Windows.
5. Optionally add a `phpcs.xml.dist` file to the package root to enable code style and best practice checks using PHP\_CodeSniffer.

    Example of a minimal custom ruleset based on the defaults set in the WP-CLI testing framework:

    ```

    Custom ruleset for WP-CLI PROJECT NAME

        .

    ```

    All other [PHPCS configuration options](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Annotated-Ruleset) are, of course, available.
6. Update your composer dependencies and regenerate your autoloader and binary folders:

    ```
    composer update
    ```

You are now ready to use the testing framework from within your package.

### Launching the tests

[](#launching-the-tests)

You can use the following commands to control the tests:

- `composer prepare-tests` - Set up the database that is needed for running the functional tests. This is only needed once.
- `composer test` - Run all test suites.
- `composer lint` - Run only the linting test suite.
- `composer phpcs` - Run only the code sniffer test suite.
- `composer phpcbf` - Run only the code sniffer cleanup.
- `composer phpunit` - Run only the unit test suite.
- `composer behat` - Run only the functional test suite.

### Controlling what to test

[](#controlling-what-to-test)

To send one or more arguments to one of the test tools, prepend the argument(s) with a double dash. As an example, here's how to run the functional tests for a specific feature file only:

```
composer behat -- features/cli-info.feature
```

Prepending with the double dash is needed because the arguments would otherwise be sent to Composer itself, not the tool that Composer executes.

### Controlling the test environment

[](#controlling-the-test-environment)

#### WordPress Version

[](#wordpress-version)

You can run the tests against a specific version of WordPress by setting the `WP_VERSION` environment variable.

This variable understands any numeric version, as well as the special terms `latest` and `trunk`.

Note: This only applies to the Behat functional tests. All other tests never load WordPress.

Here's how to run your tests against the latest trunk version of WordPress:

```
WP_VERSION=trunk composer behat
```

#### WP-CLI Binary

[](#wp-cli-binary)

You can run the tests against a specific WP-CLI binary, instead of using the one that has been built in your project's `vendor/bin` folder.

This can be useful to run your tests against a specific Phar version of WP\_CLI.

To do this, you can set the `WP_CLI_BIN_DIR` environment variable to point to a folder that contains an executable `wp` binary. Note: the binary has to be named `wp` to be properly recognized.

As an example, here's how to run your tests against a specific Phar version you've downloaded.

```
# Prepare the binary you've downloaded into the ~/wp-cli folder first.
mv ~/wp-cli/wp-cli-1.2.0.phar ~/wp-cli/wp
chmod +x ~/wp-cli/wp

WP_CLI_BIN_DIR=~/wp-cli composer behat
```

### Setting up the tests in Travis CI

[](#setting-up-the-tests-in-travis-ci)

Basic rules for setting up the test framework with Travis CI:

- `composer prepare-tests` needs to be called once per environment.
- `linting and sniffing` is a static analysis, so it shouldn't depend on any specific environment. You should do this only once, as a separate stage, instead of per environment.
- `composer behat || composer behat-rerun` causes the Behat tests to run in their entirety first, and in case their were failed scenarios, a second run is done with only the failed scenarios. This usually gets around intermittent issues like timeouts or similar.

Here's a basic setup of how you can configure Travis CI to work with the test framework (extract):

```
install:
  - composer install
  - composer prepare-tests

script:
  - composer phpunit
  - composer behat || composer behat-rerun

jobs:
  include:
    - stage: sniff
      script:
        - composer lint
        - composer phpcs
      env: BUILD=sniff
    - stage: test
      php: 7.2
      env: WP_VERSION=latest
    - stage: test
      php: 7.2
      env: WP_VERSION=3.7.11
    - stage: test
      php: 7.2
      env: WP_VERSION=trunk
```

#### WP-CLI version

[](#wp-cli-version)

You can point the tests to a specific version of WP-CLI through the `WP_CLI_BIN_DIR` constant:

```
WP_CLI_BIN_DIR=~/my-custom-wp-cli/bin composer behat
```

#### WordPress version

[](#wordpress-version-1)

If you want to run the feature tests against a specific WordPress version, you can use the `WP_VERSION` constant:

```
WP_VERSION=4.2 composer behat
```

The `WP_VERSION` constant also understands the `latest` and `trunk` as valid version targets.

#### The database credentials

[](#the-database-credentials)

By default, the tests are run in a database named `wp_cli_test` with the user also named `wp_cli_test` with password `password1`. This should be set up via the `composer prepare-tests` command.

The following environment variables can be set to override the default database credentials.

- `WP_CLI_TEST_DBHOST` is the host to use and can include a port, i.e "127.0.0.1:33060" (defaults to "localhost")
- `WP_CLI_TEST_DBROOTUSER` is the user that has permission to administer databases and users (defaults to "root").
- `WP_CLI_TEST_DBROOTPASS` is the password to use for the above user (defaults to an empty password).
- `WP_CLI_TEST_DBNAME` is the database that the tests run under (defaults to "wp\_cli\_test").
- `WP_CLI_TEST_DBUSER` is the user that the tests run under (defaults to "wp\_cli\_test").
- `WP_CLI_TEST_DBPASS` is the password to use for the above user (defaults to "password1").
- `WP_CLI_TEST_DBTYPE` is the database engine type to use, i.e. "sqlite" for running tests on SQLite instead of MySQL (defaults to "mysql").
- `WP_CLI_TEST_OBJECT_CACHE` is the persistent object cache backend to use. Only supports "sqlite".

Environment variables can be set for the whole session via the following syntax: `export WP_CLI_TEST_DBNAME=custom_db`.

They can also be set for a single execution by prepending them before the Behat command: `WP_CLI_TEST_DBNAME=custom_db composer behat`.

Contributing
------------

[](#contributing)

We appreciate you taking the initiative to contribute to this project.

Contributing isn’t limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation.

For a more thorough introduction, [check out WP-CLI's guide to contributing](https://make.wordpress.org/cli/handbook/contributing/). This package follows those policy and guidelines.

### Reporting a bug

[](#reporting-a-bug)

Think you’ve found a bug? We’d love for you to help us get it fixed.

Before you create a new issue, you should [search existing issues](https://github.com/wp-cli/wp-cli-tests/issues?q=label%3Abug%20) to see if there’s an existing resolution to it, or if it’s already been fixed in a newer version.

Once you’ve done a bit of searching and discovered there isn’t an open or fixed issue for your bug, please [create a new issue](https://github.com/wp-cli/wp-cli-tests/issues/new). Include as much detail as you can, and clear steps to reproduce if possible. For more guidance, [review our bug report documentation](https://make.wordpress.org/cli/handbook/bug-reports/).

### Creating a pull request

[](#creating-a-pull-request)

Want to contribute a new feature? Please first [open a new issue](https://github.com/wp-cli/wp-cli-tests/issues/new) to discuss whether the feature is a good fit for the project.

Once you've decided to commit the time to seeing your pull request through, [please follow our guidelines for creating a pull request](https://make.wordpress.org/cli/handbook/pull-requests/) to make sure it's a pleasant experience. See "[Setting up](https://make.wordpress.org/cli/handbook/pull-requests/#setting-up)" for details specific to working on this package locally.

### License

[](#license)

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

Support
-------

[](#support)

GitHub issues aren't for general support questions, but there are other venues you can try:

###  Health Score

70

—

ExcellentBetter than 100% of packages

Maintenance95

Actively maintained with recent releases

Popularity56

Moderate usage in the ecosystem

Community45

Growing community involvement

Maturity75

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~22 days

Recently: every ~14 days

Total

130

Last Release

16d ago

Major Versions

v0.1.0 → v2.0.02018-08-05

v2.1.21 → v3.0.02021-02-18

v3.2.7 → v4.0.02023-08-30

v4.3.16 → v5.0.02025-07-03

PHP version history (3 changes)v0.1.0PHP &gt;=5.4

v2.1.17PHP &gt;=5.6

v5.0.0PHP &gt;=7.2.24

### Community

Maintainers

![](https://www.gravatar.com/avatar/6dde7f578e5530884238e7173f768ae3a890b6d66eb99262a82f2c494a1b67d4?d=identicon)[schlessera](/maintainers/schlessera)

---

Top Contributors

[![danielbachhuber](https://avatars.githubusercontent.com/u/36432?v=4)](https://github.com/danielbachhuber "danielbachhuber (732 commits)")[![schlessera](https://avatars.githubusercontent.com/u/83631?v=4)](https://github.com/schlessera "schlessera (476 commits)")[![scribu](https://avatars.githubusercontent.com/u/225715?v=4)](https://github.com/scribu "scribu (232 commits)")[![swissspidy](https://avatars.githubusercontent.com/u/841956?v=4)](https://github.com/swissspidy "swissspidy (221 commits)")[![scribu-commits](https://avatars.githubusercontent.com/u/282080004?v=4)](https://github.com/scribu-commits "scribu-commits (114 commits)")[![gitlost](https://avatars.githubusercontent.com/u/481982?v=4)](https://github.com/gitlost "gitlost (77 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (32 commits)")[![miya0001](https://avatars.githubusercontent.com/u/309946?v=4)](https://github.com/miya0001 "miya0001 (22 commits)")[![jrfnl](https://avatars.githubusercontent.com/u/663378?v=4)](https://github.com/jrfnl "jrfnl (20 commits)")[![GaryJones](https://avatars.githubusercontent.com/u/88371?v=4)](https://github.com/GaryJones "GaryJones (18 commits)")[![mrsdizzie](https://avatars.githubusercontent.com/u/1669571?v=4)](https://github.com/mrsdizzie "mrsdizzie (15 commits)")[![janw-me](https://avatars.githubusercontent.com/u/1026882?v=4)](https://github.com/janw-me "janw-me (10 commits)")[![aaemnnosttv](https://avatars.githubusercontent.com/u/1621608?v=4)](https://github.com/aaemnnosttv "aaemnnosttv (10 commits)")[![nyordanov](https://avatars.githubusercontent.com/u/192220?v=4)](https://github.com/nyordanov "nyordanov (9 commits)")[![wojsmol](https://avatars.githubusercontent.com/u/4176111?v=4)](https://github.com/wojsmol "wojsmol (8 commits)")[![ernilambar](https://avatars.githubusercontent.com/u/2098823?v=4)](https://github.com/ernilambar "ernilambar (8 commits)")[![NateWr](https://avatars.githubusercontent.com/u/2306629?v=4)](https://github.com/NateWr "NateWr (8 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (8 commits)")[![jacklowrie](https://avatars.githubusercontent.com/u/15655893?v=4)](https://github.com/jacklowrie "jacklowrie (6 commits)")[![mwilliamson](https://avatars.githubusercontent.com/u/391876?v=4)](https://github.com/mwilliamson "mwilliamson (6 commits)")

---

Tags

behatclifunctionalhacktoberfestlinterphpcsphpunitsniffertestingunitwp-clicliwordpress

### Embed Badge

![Health badge](/badges/wp-cli-wp-cli-tests/health.svg)

```
[![Health](https://phpackages.com/badges/wp-cli-wp-cli-tests/health.svg)](https://phpackages.com/packages/wp-cli-wp-cli-tests)
```

###  Alternatives

[drupal/core-dev

require-dev dependencies from drupal/drupal; use in addition to drupal/core-recommended to run tests from drupal/core.

2022.0M321](/packages/drupal-core-dev)[mglaman/phpstan-drupal

Drupal extension and rules for PHPStan

20830.6M166](/packages/mglaman-phpstan-drupal)[acquia/orca

A tool for testing a company's software packages together in the context of a realistic, functioning, best practices Drupal build

30914.4k](/packages/acquia-orca)[youwe/testing-suite

Contains Youwe's default testing packages for php.

13186.2k8](/packages/youwe-testing-suite)[yoast/yoastcs

PHP\_CodeSniffer rules for Yoast projects

221.2M33](/packages/yoast-yoastcs)[infinum/eightshift-coding-standards

Eightshift WordPress Coding Standards

1789.1k5](/packages/infinum-eightshift-coding-standards)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
