PHPackages                             yoast/wp-test-utils - 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. yoast/wp-test-utils

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

yoast/wp-test-utils
===================

PHPUnit cross-version compatibility layer for testing plugins and themes build for WordPress

1.2.1(3mo ago)632.3M↑13.8%220BSD-3-ClausePHPPHP &gt;=5.6CI passing

Since Nov 13Pushed 1mo ago14 watchersCompare

[ Source](https://github.com/Yoast/wp-test-utils)[ Packagist](https://packagist.org/packages/yoast/wp-test-utils)[ Docs](https://github.com/Yoast/wp-test-utils/)[ RSS](/packages/yoast-wp-test-utils/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (17)Used By (20)

WP Test Utils
=============

[](#wp-test-utils)

[![Version](https://camo.githubusercontent.com/0e798789e63c9f2797c9b412ea6a8962cf2db069d0836d45285ab557091b09d1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f796f6173742f77702d746573742d7574696c73)](https://packagist.org/packages/yoast/wp-test-utils)[![CS Build Status](https://github.com/Yoast/wp-test-utils/actions/workflows/cs.yml/badge.svg)](https://github.com/Yoast/wp-test-utils/actions/workflows/cs.yml)[![Test Build Status](https://github.com/Yoast/wp-test-utils/actions/workflows/test.yml/badge.svg)](https://github.com/Yoast/wp-test-utils/actions/workflows/test.yml)[![Coverage Status](https://camo.githubusercontent.com/4d327a62b6fdecba597789177a2b1fec787b91d03cf41d1633d7ff9d64764da1/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f596f6173742f77702d746573742d7574696c732f62616467652e7376673f6272616e63683d646576656c6f70)](https://coveralls.io/github/Yoast/wp-test-utils?branch=develop)

[![Minimum PHP Version](https://camo.githubusercontent.com/ac1a17db738bf6299a9e605e26855e1f7a2e234ed75e8aba19196743aedbdd0e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f796f6173742f77702d746573742d7574696c732e7376673f6d61784167653d33363030)](https://packagist.org/packages/yoast/wp-test-utils)[![License: BSD3](https://camo.githubusercontent.com/bbaaa51f7fea1b3695694722d25d68b2b9f78785f042e98eb9819ed6910fb9a4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f796f6173742f77702d746573742d7574696c73)](https://github.com/Yoast/wp-test-utils/blob/main/LICENSE)

This library contains a set of utilities for running automated tests for WordPress plugins and themes.

- [Requirements](#requirements)
- [Installation](#installation)
- [Features](#features)
    - [Utilities for running tests using BrainMonkey](#utilities-for-running-tests-using-brainmonkey)
        - [Basic `TestCase` for use with BrainMonkey](#basic-testcase-for-use-with-brainmonkey)
        - [Yoast TestCase for use with BrainMonkey](#yoast-testcase-for-use-with-brainmonkey)
        - [Bootstrap file for use with BrainMonkey](#bootstrap-file-for-use-with-brainmonkey)
        - [Helpers to create test doubles for unavailable classes](#helpers-to-create-test-doubles-for-unavailable-classes)
    - [Utilities for running integration tests with WordPress](#utilities-for-running-integration-tests-with-wordpress)
        - [What these utilities solve](#what-these-utilities-solve)
        - [Basic `TestCase` for WordPress integration tests](#basic-testcase-for-wordpress-integration-tests)
        - [Bootstrap utility functions and custom autoloader](#bootstrap-utility-functions-and-custom-autoloader)
    - [Test Helpers](#test-helpers)
        - [`Yoast\WPTestUtils\Helpers\EscapeOutputHelper` trait](#yoastwptestutilshelpersescapeoutputhelper-trait)
- [Contributing](#contributing)
- [License](#license)

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

[](#requirements)

- PHP 5.6 or higher.

The following packages will be automatically required via Composer:

- [PHPUnit Polyfills](https://packagist.org/packages/yoast/phpunit-polyfills) 1.1.5 or higher.
- [PHPUnit](https://packagist.org/packages/phpunit/phpunit) 5.7 - 9.x.
- [BrainMonkey](https://packagist.org/packages/brain/monkey) 2.7.0 or higher.

Installation
------------

[](#installation)

To install this package, run:

```
composer require --dev yoast/wp-test-utils
```

To update this package, run:

```
composer update --dev yoast/wp-test-utils --with-dependencies
```

Features
--------

[](#features)

This library contains a set of utilities for running automated tests for WordPress plugins and themes.

### Utilities for running tests using BrainMonkey

[](#utilities-for-running-tests-using-brainmonkey)

#### Basic `TestCase` for use with BrainMonkey

[](#basic-testcase-for-use-with-brainmonkey)

Features of this `TestCase`:

1. Cross-version compatibility with PHPUnit 5.7 - 9.x via the [PHPUnit Polyfills](https://packagist.org/packages/yoast/phpunit-polyfills) package.
2. The BrainMonkey and Mockery set up and tear down is already handled.
3. Tests using Mockery expectations will not be marked as "risky", even when there are no assertions.
4. Makes alternative implementations of the BrainMonkey native [`stubTranslationFunctions()`](https://giuseppe-mazzapica.gitbook.io/brain-monkey/functions-testing-tools/function-stubs#pre-defined-stubs-for-translation-functions) and [`stubEscapeFunctions()`](https://giuseppe-mazzapica.gitbook.io/brain-monkey/functions-testing-tools/function-stubs#pre-defined-stubs-for-escaping-functions) functions available.
    The BrainMonkey native functions create stubs which will apply basic HTML escaping if the stubbed function is an escaping function, like `esc_html__()`.
    The alternative implementations of these functions will create stubs which will return the original value without change. This makes creating tests easier as the `$expected` value does not need to account for the HTML escaping.
    *Note: the alternative implementation should be used selectively.*
5. Helper functions for [setting expectations for generated output](#yoastwptestutilshelpersescapeoutputhelper-trait).
6. Helper functions for [creating "dummy" test doubles for unavailable classes](#helpers-to-create-test-doubles-for-unavailable-classes).

***Implementation example:***

```
