Skip to content

Commit 55c704c

Browse files
authored
Update the guide per latest release
1 parent e8680a6 commit 55c704c

1 file changed

Lines changed: 20 additions & 19 deletions

File tree

for/wordpress.md

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,20 @@ WPBrowser will install the latest version of Codeception for you.
4242
## Setup
4343

4444
To fully use the WordPress specific modules of the WPBrowser suite you need to setup a local WordPress installation; this is in no way different from what's required to locally develop a WordPress theme or plugin.
45-
In the examples below I assume that the local WordPress installation root directory is `/var/www/wordpress`, that it responds at the `http://wordpress.dev` URL and that I am developing a plugin called "Acme Plugin".
46-
While it's possible to start from a default Codeception configuration the WPBrowser package comes with its own CLI tool (`wpcept`) and its own bootstrap command.
47-
Scaffold the tests using the latter
45+
In the examples below I assume that the local WordPress installation root directory is `/var/www/wordpress`, that it responds at the `http://wordpress.localhost` URL and that I am developing a plugin called "Acme Plugin".
46+
While it's possible to start from a default Codeception configuration the WPBrowser package comes with its own initialization template that can be called using:
4847

4948
```bash
50-
wpcept bootstrap
49+
codecept init wpbrowser
5150
```
5251

53-
The command creates the `tests` directory and scaffold the `acceptance`, `functional`, `integration` and `unit` suites creating a `tests` sub-directory and a configuration file for each.
54-
Edit the `codeception.yml` file to match your local WordPress setup and point the modules to the local WordPress installation folder, the local WordPress URL and so on.
52+
The command offers the possibility to scaffold an empty suite or to undergo an interactive setup that will end in a ready to run Codeception for WordPress installation; it will create the `tests` directory and scaffold the `acceptance`, `functional`, `wpunit` and `unit` suites creating a `tests` sub-directory and a configuration file for each.
53+
If you did not use the step-by-step initialization then edit each suite configuration file (e.g. `tests/functional.suite.yml` for the functional suite) to match your local WordPress setup and point the modules to the local WordPress installation folder, the local WordPress URL and so on.
5554
If you are using the `WPLoader` module in your tests take care to create a dedicated database for it and not to use the same database the `Db` or `WPDb` modules might use.
5655
The use of the modules defined in the WPBrowser package is not tied to this bootstrap though so feel free to set up Codeception in any other way.
5756

5857
## Integration Tests
59-
Commonly "WordPress unit tests" are not related to classical unit tests but to integration tests. The difference is that unit tests are supposed to test a class methods in complete isolation, while integration tests check how components work inside WordPress. That's why, to prepare WordPress for testing, you should enable `WPLoader` module into `integration.suite.yml`.
58+
Commonly "WordPress unit tests" (hence the `wpunit` default name of the suite) are not related to classical unit tests but to integration tests. The difference is that unit tests are supposed to test a class methods in complete isolation, while integration tests check how components work inside WordPress. That's why, to prepare WordPress for testing, you should enable `WPLoader` module into `wpunit.suite.yml`.
6059
The `WPLoader` module: it takes care of loading, installing and configuring a fresh WordPress installation before each test method runs.
6160
To handle the heavy lifting the module requires some information about the local WordPress installation: in the `codeception.yml` file configure it to match your local setup; with reference to the example above the module configuration might be:
6261

@@ -71,17 +70,17 @@ modules:
7170
dbPassword: root
7271
wpDebug: true
7372
tablePrefix: wptests_
74-
domain: wordpress.dev
73+
domain:wordpress.localhost
7574
plugins:
7675
- acme-plugin/plugin.php
7776
activatePlugins:
7877
- acme-plugin/plugin.php
7978
```
8079
81-
The module is wrapping and augmenting the [WordPress Core automated testing suite](https://make.wordpress.org/core/handbook/testing/automated-testing/phpunit/) and to generate a test case that uses Codeception and the methods provided by the Core testing suite you can use the `wpcept` command again:
80+
The module is wrapping and augmenting the [WordPress Core automated testing suite](https://make.wordpress.org/core/handbook/testing/automated-testing/phpunit/) and to generate a test case that uses Codeception and the methods provided by the Core testing suite you can use the generation command provided by the package:
8281
8382
```bash
84-
wpcept generate:wpunit integration "Acme\SomeClass"
83+
codecept generate:wpunit integration "Acme\SomeClass"
8584
```
8685

8786
The generated test case extends the `WPTestCase` class and it exposes all the mehtods defined by `Codeception\Test\Unit` test case and the Core suite `\WP_UnitTestCase`.
@@ -96,27 +95,29 @@ Any database interaction is wrapped in a transaction to guarantee isolation betw
9695

9796
## WordPress Functional Tests
9897
Functional tests are meant to test requests handling and end-to-end interactions.
99-
WPBrowser will scaffold functional tests to use the `WPBrowser`, `WPDb` and `Filesystem` modules.
100-
While the latter is the one defined by the Codeception suite `WPBrowser` and `WPDb` modules extend the Codeception `PHPBrowser` and `Db` modules with WordPress specific methods.
98+
WPBrowser will scaffold functional tests to use the `WordPress`, `WPDb` and `Filesystem` modules.
99+
While the latter is the one defined by the Codeception suite `WordPress` and `WPDb` modules extend the Codeception framework and `Db` modules with WordPress specific methods.
101100
The modules will require some WordPress specific setup parameters:
102101

103102
```yaml
104103
modules:
105104
enabled:
106-
WPBrowser:
107-
url: 'http://wordpress.dev'
108-
adminUsername: admin
109-
adminPassword: password
110-
adminUrl: /wp-admin
105+
- Filesystem
111106
WPDb:
112107
dsn: 'mysql:host=localhost;dbname=wordpress'
113108
user: root
114109
password: root
115110
dump: tests/_data/wp.sql
116111
populate: true
117112
cleanup: true
118-
url: 'http://wordpress.dev'
113+
url: 'http://wordpress.localhost'
119114
tablePrefix: wp_
115+
WordPress:
116+
depends: WPDb
117+
wpRootFolder: /var/www/wordpress
118+
adminUsername: admin
119+
adminPassword: password
120+
adminPath: /wp-admin
120121
```
121122
122123
To generate a functional test use the default `codecept` commmand.
@@ -141,7 +142,7 @@ The modules require some WordPress specific parameters to work:
141142
modules:
142143
enabled:
143144
WPWebDriver:
144-
url: 'http://wordpress.dev'
145+
url: 'http://wordpress.localhost'
145146
browser: phantomjs
146147
port: 4444
147148
restart: true

0 commit comments

Comments
 (0)