PHPackages                             automattic/behat-wp-env-context - 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. automattic/behat-wp-env-context

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

automattic/behat-wp-env-context
===============================

Shared Behat FeatureContext for wp-env based WordPress plugin testing

v0.1.1(4mo ago)0419GPL-2.0-or-laterPHPPHP &gt;=7.4

Since Dec 13Pushed 4mo agoCompare

[ Source](https://github.com/Automattic/behat-wp-env-context)[ Packagist](https://packagist.org/packages/automattic/behat-wp-env-context)[ Docs](https://github.com/Automattic/behat-wp-env-context)[ RSS](/packages/automattic-behat-wp-env-context/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (3)Used By (0)

Automattic Behat WP-Env Context
===============================

[](#automattic-behat-wp-env-context)

Shared Behat testing infrastructure for WordPress plugins using wp-env.

This package provides a reusable base FeatureContext class that eliminates 300-400 lines of boilerplate from each plugin's Behat tests.

Why This Package?
-----------------

[](#why-this-package)

When migrating from the deprecated `wp-cli/wp-cli-tests` framework to wp-env, many Automattic plugins ended up duplicating similar test infrastructure code. This package consolidates that into a single, battle-tested implementation.

### Benefits

[](#benefits)

- ✅ **~450 lines** of production-ready, reusable code
- ✅ **wp-env output filtering** automatically handles status messages (ℹ, ✔, ✖)
- ✅ **Multi-line error parsing** for accurate STDERR assertions
- ✅ **Variable substitution** for dynamic test values (`{POST_ID}`, `{TERM_ID}`, etc.)
- ✅ **Database cleanup** ensures test isolation without slow fresh installs
- ✅ **MU-plugin helpers** for test environment setup
- ✅ **Extensible** via abstract methods and protected properties
- ✅ **Standard step definitions** work out of the box

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

[](#installation)

```
composer require --dev automattic/behat-wp-env-context
```

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

[](#requirements)

- PHP 7.4+
- Node.js (for wp-env)
- `@wordpress/env` installed globally or in `package.json`
- `behat/behat` ^3.7

Quick Start
-----------

[](#quick-start)

### 1. Create Your FeatureContext

[](#1-create-your-featurecontext)

**File:** `tests/Behat/FeatureContext.php`

```
