PHPackages                             10up/wp-codeception - 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. 10up/wp-codeception

AbandonedArchivedWordpress-plugin[Testing &amp; Quality](/categories/testing)

10up/wp-codeception
===================

The WordPress Plugin which integrates with the Codeception PHP testing framework and allows you to write and run Codeception tests for WordPress via WP CLI.

1.0.3(10y ago)1014.2k11[7 issues](https://github.com/10up/wp-codeception/issues)[1 PRs](https://github.com/10up/wp-codeception/pulls)PHPPHP &gt;=5.4.0

Since May 18Pushed 4y ago134 watchersCompare

[ Source](https://github.com/10up/wp-codeception)[ Packagist](https://packagist.org/packages/10up/wp-codeception)[ RSS](/packages/10up-wp-codeception/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (3)Versions (10)Used By (0)

WP Codeception
==============

[](#wp-codeception)

> This is a WordPress Plugin which integrates with the [Codeception](http://codeception.com/) PHP testing framework and allows you to write and run Codeception tests for WordPress via WP CLI.

[![Support Level](https://camo.githubusercontent.com/bda18bd40847957c7c2fd168847c0be1c844a01a7e8938bbadef330bcd0f6790/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f737570706f72742d61726368697665642d7265642e737667)](#support-level)

We're working towards supporting all of [Codeceptions commands](http://codeception.com/docs/reference/Commands). If you find one we haven't included yet, please submit a [Pull Request](https://github.com/10up/wp-codeception/pulls)!

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

[](#installation)

[Download the latest version](https://github.com/10up/wp-codeception/archive/master.zip) and extract, or clone the repository with Git into a new directory `wp-content/plugins/wp-codeception` in your WordPress install.

#### Install required node modules and composer dependencies

[](#install-required-node-modules-and-composer-dependencies)

We'll run our commands from within [VVV](https://github.com/Varying-Vagrant-Vagrants/VVV) because WP CLI, Node, and Composer are already installed for us there.

```
$ vagrant up
$ vagrant ssh
$ sudo apt-get install openjdk-7-jre-headless
$ cd /srv/www/yoursite/htdocs/wp-content/plugins/wp-codeception
$ composer install
$ wp plugin activate wp-codeception
```

Afterwards you'll have a new `vendor` directory within your `plugins/wp-codeception` directory which contains all the code libraries we're dependant on.

#### Install as a composer dependency

[](#install-as-a-composer-dependency)

There is an alternative way to install this plugin. You can add it as a composer dependency for your project. To do it, run following command in your terminal:

```
$ composer require 10up/wp-codeception
```

This command will install the plugin and all its dependencies for your project. Please, pay attention that if you already use [composer/installers](https://github.com/composer/installers) dependency in your project, then `wp-codeception` will be installed into `/wp-content/plugins/wp-codeception/` folder. It happens, because `wp-codeception` has `wordpress-plugin` type and will be processed by `composer/installers` accordingly (read its documentation for more details).

If you want to add it as a dependency to your plugin or theme, you will need to update your `composer.json` file and tell it where to install `wp-codeception`. You can achieve it by providing `installer-paths` instructions like in the snippet below.

```
{
    ...,
    "extra": {
        "installer-paths": {
            "vendor/{$name}/": ["type:wordpress-plugin"]
        }
    },
    ...
}
```

Now `composer/installers` will know to install wordpress plugins into *vendor* folder. The final step which you need to do is to update your `autoload` section and add `wp-codeception.php` file to the autoload files list.

```
{
    ...,
    "autoload": {
        "psr-X": {
            ...
        },
        "files": [
            ...,
            "vendor/wp-codeception/wp-codeception.php"
        ]
    },
    ...
}
```

#### Install the test suite

[](#install-the-test-suite)

See the [Codeception bootstrapping documentation](http://codeception.com/docs/reference/Commands#Bootstrap) for further information.

```
# You'll create the test suite in your own plugin or theme directory..
$ cd /srv/www/yoursite/htdocs/wp-content/{your plugin or theme directory}
$ wp codeception bootstrap
```

Afterwards you'll have a new `tests` directory within your plugin or theme directory. This is your new test suite, and where you'll write all your tests.

Writing Tests
-------------

[](#writing-tests)

You can write tests using any of the three [Codeception](http://codeception.com/) testing frameworks: [Acceptance](http://codeception.com/docs/03-AcceptanceTests), [Functional](http://codeception.com/docs/04-FunctionalTests) and [Unit](http://codeception.com/docs/05-UnitTests) testing. If you look within the new `tests` directory you'll see three config files; one for each test framework (acceptance.suite.yml, functional.suite.yml, unit.suite.yml). Edit these files as you wish.

#### Generate your first test

[](#generate-your-first-test)

```
# You should be in the plugin or theme directory where you ran the bootstrap
$ wp codeception generate-(cept|cest) (acceptance|functional|unit) MyTestName

# Example
$ wp codeception generate-cept acceptance LoginTest
```

Afterwards you'll have a new file in your plugin or theme directory `tests/acceptance/LoginTest.php`, where you can write your first test. Remember, any Codeception test will work here! For example, you could run any of the [acceptance test examples](http://codeception.com/docs/03-AcceptanceTests) mentioned in the Codeception documentation. Likewise, the same goes for [Functional](http://codeception.com/docs/04-FunctionalTests) and [Unit tests](http://codeception.com/docs/05-UnitTests).

#### Example: Writing a Login Acceptance Test

[](#example-writing-a-login-acceptance-test)

```
