PHPackages                             stephenharris/wordpress-behat-extension - 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. stephenharris/wordpress-behat-extension

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

stephenharris/wordpress-behat-extension
=======================================

WordPress extension for Behat 3

0.4.0(9y ago)81315[8 issues](https://github.com/stephenharris/WordPressBehatExtension/issues)[2 PRs](https://github.com/stephenharris/WordPressBehatExtension/pulls)MITPHP

Since Apr 11Pushed 9y ago3 watchersCompare

[ Source](https://github.com/stephenharris/WordPressBehatExtension)[ Packagist](https://packagist.org/packages/stephenharris/wordpress-behat-extension)[ RSS](/packages/stephenharris-wordpress-behat-extension/feed)WikiDiscussions develop Synced 2w ago

READMEChangelogDependencies (16)Versions (12)Used By (0)

WordPress Extension for Behat 3
-------------------------------

[](#wordpress-extension-for-behat-3)

This is a Behat 3.0 Extension for WordPress plugin and theme development.

The Extension allows you to use WordPress functions in your context class if you include `StephenHarris\WordPressBehatExtension\Context\WordPressContext` (or create and include a child class of it, i.e. make your `FeatureContext` ).

It also provides [other contexts](docs/Contexts.md).

**Version:** 0.4.0 . *This project follows [SemVer](http://semver.org/)*.

History
-------

[](#history)

This repository started off as a fork of:

-
- itself a fork of
- itself a fork of

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

[](#installation)

*(For 'quick start' guides, please see the [Recipes](docs/Recipes.md)).*

1. Add a composer development requirement for your WordPress theme or plugin:

    ```
    {
        "repositories": [
            {
                "type": "vcs",
                "url": "https://github.com/stephenharris/WordPressBehatExtension.git"
            }
        ],
        "require-dev" : {
            "stephenharris/wordpress-behat-extension": "~0.3",
            "behat/mink-goutte-driver": "~1.1",
            "behat/mink-selenium2-driver": "~1.3.1",
            "johnpbloch/wordpress": "~4.6.1"
        }
    }
    ```

    You don't *have* to install WordPress via composer. But you shall need a path to a WordPress install below. Additionally you don't *have* to use the Goutte and Selenium2 drivers, but these are the most common.
2. Add the following Behat configuration file below. You will need:

- The path to your WordPress install (here assumed `vendor/wordpress`, relative to your project's root directory).
- The database, and database username and password of your WordPress install (here assumed `wordress_test`, `root`, `''`)
- The URL of your WordPress install (In this example we'll be using php's build in server)
- A temporary directory to store e-mails that are 'sent'

    ```
    default:
      suites:
        default:
          contexts:
            - FeatureContext
            - \StephenHarris\WordPressBehatExtension\Context\WordPressContext
            - \StephenHarris\WordPressBehatExtension\Context\Plugins\WordPressPluginContext
            # and any other contexts you need, please see the documentation
      extensions:
        StephenHarris\WordPressBehatExtension:
          path: '%paths.base%/vendor/wordpress'
          connection:
            host: 'localhost'
            db: 'wordpress_test'
            username: 'root'
            password: ''
          mail:
            directory: '/tmp/mail'
        Behat\MinkExtension:
          base_url:    'http://localhost:8000'
          goutte: ~
          selenium2: ~
    ```

    *Note the `StephenHarris\WordPressBehatExtension\Context\WordPressContext` context included. This will cause WordPress to be loaded, and all its functions available in your context classes.*. You can also include [other contexts](docs/Contexts.md).

3. Install the vendors and initialize behat test suites

    ```
    composer update
    # You will need to ensure a WordPress install is available, with database credentials that
    # mach the configuration file above
    vendor/bin/behat --init
    ```
4. Write some Behat features in your project's `features` directory and define any steps. The `WordPressContext` context will make all WordPress functions available in your context classes (but there is a better way).

    ```
    Feature: Manage plugins
        In order to manage plugins
        As an admin
        I need to enable and disable plugins

        Background:
            Given I have a vanilla wordpress installation
                | name          | email                   | username | password |
                | BDD WordPress | your@email.com          | admin    | test     |
            And I am logged in as "admin" with password "test"

        Scenario: Enable the dolly plugin
            Given there are plugins
                | plugin    | status  |
                | hello.php | enabled |
            When I go to "/wp-admin/"
            Then I should see a "#dolly" element

        Scenario: Disable the dolly plugin
            Given there are plugins
                | plugin    | status   |
                | hello.php | disabled |
            When I go to "/wp-admin/"
            Then I should not see a "#dolly" element

    ```
5. Run the tests

> In our example, since we using PHP's built-in web sever, this will need to be started so that Behat can access our site.

> ```
> ```

```
php -S localhost:8000 -t vendor/wordpress -d disable_functions=mail
```

```bash
vendor/bin/behat
```

```

Documentation
-------------

[](#documentation)

Please see the [Docs](docs/Contents.md).

Aim
---

[](#aim)

The aim of this project is to provide a collection of context classes that allow for easy testing of WordPress' core functionality. Those contexts can then be built upon to test your site/plugin/theme-specific functionality.

License
-------

[](#license)

WordPressBehatExtension is open source and released under MIT license. See [LICENSE](LICENSE) file for more info.

Health Warning
--------------

[](#health-warning)

This is not to be used on a live site. Your database **will** be cleared of all data.

Currently this extension also over-rides your `wp-config.php` but this implementation may change in the future.

The extension installs three `mu-plugins` into your install (which it assumes is at `{site-path}/wp-content/mu-plugins`). These plug-ins do the following:

- `wp-mail.php` - over-rides `wp_mail()` function to store the e-mails locally
- `wp-install.php` - over-rides `wp_install_defaults()` to prevent any default content being created, with the exception of the 'Uncategorised' category.
- `move-admin-bar-to-back.php` - a workaround for [\#1](https://github.com/stephenharris/WordPressBehatExtension/issues/1) which prevent elements from being hidden from Selenium behind the admin menu bar.

Changelog
---------

[](#changelog)

A changelog can be found at [CHANGELOG.md](./CHANGELOG.md).

How to help
-----------

[](#how-to-help)

This project needs a lot of love :). You can help by doing any of the following

- Opening an issue to request a context / step definitions
- Submitting a PR to add a context / step definition
- Submiting a PR to add to or improve the documentation
- Opening an issue you have questions or find any bugs
- Just using this extension in your development / testing workflow and providing your feedback

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 75.1% of commits — single point of failure

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 ~46 days

Total

4

Last Release

3531d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/00d5900d269dab58816954d5db3d61ee200eec39565c8cb8f3caccd165b64441?d=identicon)[stephenharris](/maintainers/stephenharris)

---

Top Contributors

[![stephenharris](https://avatars.githubusercontent.com/u/3255034?v=4)](https://github.com/stephenharris "stephenharris (193 commits)")[![tmf](https://avatars.githubusercontent.com/u/1573003?v=4)](https://github.com/tmf "tmf (27 commits)")[![wdalmut](https://avatars.githubusercontent.com/u/551974?v=4)](https://github.com/wdalmut "wdalmut (24 commits)")[![johnbillion](https://avatars.githubusercontent.com/u/208434?v=4)](https://github.com/johnbillion "johnbillion (9 commits)")[![davidbenton](https://avatars.githubusercontent.com/u/1603279?v=4)](https://github.com/davidbenton "davidbenton (2 commits)")[![rask](https://avatars.githubusercontent.com/u/98275?v=4)](https://github.com/rask "rask (2 commits)")

---

Tags

wordpressBDDBehatstory

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/stephenharris-wordpress-behat-extension/health.svg)

```
[![Health](https://phpackages.com/badges/stephenharris-wordpress-behat-extension/health.svg)](https://phpackages.com/packages/stephenharris-wordpress-behat-extension)
```

###  Alternatives

[symfony/framework-bundle

Provides a tight integration between Symfony components and the Symfony full-stack framework

3.6k246.0M11.1k](/packages/symfony-framework-bundle)[friendsoftypo3/content-blocks

TYPO3 CMS Content Blocks - Content Types API | Define reusable components via YAML

101466.4k45](/packages/friendsoftypo3-content-blocks)[wp-cli/wp-cli-tests

WP-CLI testing framework

423.0M129](/packages/wp-cli-wp-cli-tests)[wdalmut/wordpress-extension

WordPress extension for Behat

131.4k](/packages/wdalmut-wordpress-extension)

PHPackages © 2026

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