PHPackages                             dingo-d/wp-pest-integration-test-setup - 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. [Framework](/categories/framework)
4. /
5. dingo-d/wp-pest-integration-test-setup

Abandoned → [dingo-d/wp-pest](/?search=dingo-d%2Fwp-pest)Library[Framework](/categories/framework)

dingo-d/wp-pest-integration-test-setup
======================================

A package that will add WordPress integration test suite with Pest framework

1.7.0(1y ago)12910.1k↓31.6%5[4 issues](https://github.com/dingo-d/wp-pest/issues)[1 PRs](https://github.com/dingo-d/wp-pest/pulls)1MITPHPPHP ^7.4 || ^8.0

Since May 10Pushed 1y ago3 watchersCompare

[ Source](https://github.com/dingo-d/wp-pest)[ Packagist](https://packagist.org/packages/dingo-d/wp-pest-integration-test-setup)[ RSS](/packages/dingo-d-wp-pest-integration-test-setup/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (12)Versions (20)Used By (1)

WordPress integration tests with PestPHP
========================================

[](#wordpress-integration-tests-with-pestphp)

A package that will add WordPress integration and unit test suites using [Pest PHP](https://pestphp.com/) testing framework.

Why bother?
-----------

[](#why-bother)

When somebody mentions automated testing, WordPress doesn't really come to mind, right? Hopefully, this package will help break the stigma of testing in WordPress.

This package will enable you to get up and running in no time with easy and readable testing setup using Pest PHP framework.

Requirements
------------

[](#requirements)

1. PHP &gt; 7.4
2. Composer

This package will only work with Composer, I don't plan on supporting alternative ways of installations.

Setup
-----

[](#setup)

In your project run:

```
composer require dingo-d/wp-pest-integration-test-setup --dev
```

After that you can run the following command:

```
vendor/bin/wp-pest setup theme
```

This will set up the `tests` folder, download the latest version of [WordPress develop](https://github.com/WordPress/wordpress-develop/) repo and place it in `wp` folder. It will also set up your integration and unit test suites with an example that you can run in your theme.

There are other options you can choose from by typing

```
vendor/bin/wp-pest setup --help
```

```
Description:
  Sets up the test suites.

Usage:
  setup [options] [--]

Arguments:
  project-type                     Select whether you want to setup tests for theme or a plugin. Can be "theme" or "plugin"

Options:
      --wp-version[=WP-VERSION]    Pass the version of the WordPress you want to test on. [default: "latest"]
      --plugin-slug[=PLUGIN-SLUG]  If you are setting the plugin tests provide the plugin slug.
      --skip-delete                If you are running the setup tests in a CI pipeline, provide this option to skip the deletion step.
  -h, --help                       Display help for the given command. When no command is given display help for the list command
  -q, --quiet                      Do not output any message
  -V, --version                    Display this application version
      --ansi|--no-ansi             Force (or disable --no-ansi) ANSI output
  -n, --no-interaction             Do not ask any interactive question
  -v|vv|vvv, --verbose             Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Help:
  This command helps you set up WordPress integration and unit test suites.
```

Under the hood
--------------

[](#under-the-hood)

For an in-depth reasoning and explanation of how this package came to be, you can read [this article](https://madebydenis.com/wordpress-integration-tests-with-pest-php/).

Basically what's "under the hood" is downloaded [wordpress-develop](https://github.com/WordPress/wordpress-develop) repository to your project, added an in memory DB (sql lite from [aaemnnosttv/wp-sqlite-db](https://github.com/aaemnnosttv/wp-sqlite-db)), and a base test class from [Yoast/wp-test-utils](https://github.com/Yoast/wp-test-utils). All that combined allows you to run integration tests in WordPress with Pest PHP without any additional setup.

Running unit tests alongside integration tests
----------------------------------------------

[](#running-unit-tests-alongside-integration-tests)

Due to the bug in how Pest handles [file loading](https://github.com/pestphp/pest/issues/649), in order to successfully run the unit tests, you'll need to add the following helper to either your `Pest.php` file, or your `Helpers.php` file:

```
function isUnitTest() {
	return !empty($GLOBALS['argv']) && $GLOBALS['argv'][1] === '--group=unit';
}
```

Then, in your **integration** tests, you'll need to add, before the test case `uses()` call

```
