You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: for/wordpress.md
+20-19Lines changed: 20 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,21 +42,20 @@ WPBrowser will install the latest version of Codeception for you.
42
42
## Setup
43
43
44
44
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:
48
47
49
48
```bash
50
-
wpcept bootstrap
49
+
codecept init wpbrowser
51
50
```
52
51
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.
55
54
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.
56
55
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.
57
56
58
57
## 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`.
60
59
The `WPLoader` module: it takes care of loading, installing and configuring a fresh WordPress installation before each test method runs.
61
60
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:
62
61
@@ -71,17 +70,17 @@ modules:
71
70
dbPassword: root
72
71
wpDebug: true
73
72
tablePrefix: wptests_
74
-
domain:wordpress.dev
73
+
domain:wordpress.localhost
75
74
plugins:
76
75
- acme-plugin/plugin.php
77
76
activatePlugins:
78
77
- acme-plugin/plugin.php
79
78
```
80
79
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:
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
96
95
97
96
## WordPress Functional Tests
98
97
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.
101
100
The modules will require some WordPress specific setup parameters:
102
101
103
102
```yaml
104
103
modules:
105
104
enabled:
106
-
WPBrowser:
107
-
url: 'http://wordpress.dev'
108
-
adminUsername: admin
109
-
adminPassword: password
110
-
adminUrl: /wp-admin
105
+
- Filesystem
111
106
WPDb:
112
107
dsn: 'mysql:host=localhost;dbname=wordpress'
113
108
user: root
114
109
password: root
115
110
dump: tests/_data/wp.sql
116
111
populate: true
117
112
cleanup: true
118
-
url: 'http://wordpress.dev'
113
+
url: 'http://wordpress.localhost'
119
114
tablePrefix: wp_
115
+
WordPress:
116
+
depends: WPDb
117
+
wpRootFolder: /var/www/wordpress
118
+
adminUsername: admin
119
+
adminPassword: password
120
+
adminPath: /wp-admin
120
121
```
121
122
122
123
To generate a functional test use the default `codecept` commmand.
@@ -141,7 +142,7 @@ The modules require some WordPress specific parameters to work:
0 commit comments