Skip to content

Commit c9e778d

Browse files
committed
Merge branch 'master' into fix/required-dependency-version
2 parents 239836b + 89b8328 commit c9e778d

File tree

4 files changed

+142
-5
lines changed

4 files changed

+142
-5
lines changed

.readme-partials/USING.md

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ To make use of the WP-CLI testing framework, you need to complete the following
88
2. Add the required test scripts to the `composer.json` file:
99
```json
1010
"scripts": {
11+
"behat": "run-behat-tests",
12+
"behat-rerun": "rerun-behat-tests",
1113
"lint": "run-linter-tests",
1214
"phpcs": "run-phpcs-tests",
1315
"phpunit": "run-php-unit-tests",
14-
"behat": "run-behat-tests",
1516
"prepare-tests": "install-package-tests",
1617
"test": [
1718
"@lint",
@@ -40,7 +41,7 @@ To make use of the WP-CLI testing framework, you need to complete the following
4041
```
4142
This will make sure that the automated Behat system works across all platforms. This is needed on Windows.
4243

43-
4. Update your composer dependencies and regenerate your autoloader and binary folders:
44+
5. Update your composer dependencies and regenerate your autoloader and binary folders:
4445
```bash
4546
composer update
4647
```
@@ -69,6 +70,72 @@ Prepending with the double dash is needed because the arguments would otherwise
6970

7071
### Controlling the test environment
7172

73+
#### WordPress Version
74+
75+
You can run the tests against a specific version of WordPress by setting the `WP_VERSION` environment variable.
76+
77+
This variable understands any numeric version, as well as the special terms `latest` and `trunk`.
78+
79+
Note: This only applies to the Behat functional tests. All other tests never load WordPress.
80+
81+
Here's how to run your tests against the latest trunk version of WordPress:
82+
```bash
83+
WP_VERSION=trunk composer behat
84+
```
85+
86+
#### WP-CLI Binary
87+
88+
You can run the tests against a specific WP-CLI binary, instead of using the one that has been built in your project's `vendor/bin` folder.
89+
90+
This can be useful to run your tests against a specific Phar version of WP_CLI.
91+
92+
To do this, you can set the `WP_CLI_BIN_DIR` environment variable to point to a folder that contains an executable `wp` binary. Note: the binary has to be named `wp` to be properly recognized.
93+
94+
As an example, here's how to run your tests against a specific Phar version you've downloaded.
95+
```bash
96+
# Prepare the binary you've downloaded into the ~/wp-cli folder first.
97+
mv ~/wp-cli/wp-cli-1.2.0.phar ~/wp-cli/wp
98+
chmod +x ~/wp-cli/wp
99+
100+
WP_CLI_BIN_DIR=~/wp-cli composer behat
101+
```
102+
103+
### Setting up the tests in Travis CI
104+
105+
Basic rules for setting up the test framework with Travis CI:
106+
107+
* `composer prepare-tests` needs to be called once per environment.
108+
* `linting and sniffing` is a static analysis, so it shouldn't depend on any specific environment. You should do this only once, as a separate stage, instead of per environment.
109+
* `composer behat || composer behat-rerun` causes the Behat tests to run in their entirety first, and in case their were failed scenarios, a second run is done with only the failed scenarios. This usually gets around intermittent issues like timeouts or similar.
110+
111+
Here's a basic setup of how you can configure Travis CI to work with the test framework (extract):
112+
```yml
113+
install:
114+
- composer install
115+
- composer prepare-tests
116+
117+
script:
118+
- composer phpunit
119+
- composer behat || composer behat-rerun
120+
121+
jobs:
122+
include:
123+
- stage: sniff
124+
script:
125+
- composer lint
126+
- composer phpcs
127+
env: BUILD=sniff
128+
- stage: test
129+
php: 7.2
130+
env: WP_VERSION=latest
131+
- stage: test
132+
php: 7.2
133+
env: WP_VERSION=3.7.11
134+
- stage: test
135+
php: 7.2
136+
env: WP_VERSION=trunk
137+
```
138+
72139
#### WP-CLI version
73140
74141
You can point the tests to a specific version ow WP-CLI through the `WP_CLI_BIN_DIR` constant:

README.md

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ To make use of the WP-CLI testing framework, you need to complete the following
1919
2. Add the required test scripts to the `composer.json` file:
2020
```json
2121
"scripts": {
22+
"behat": "run-behat-tests",
23+
"behat-rerun": "rerun-behat-tests",
2224
"lint": "run-linter-tests",
2325
"phpcs": "run-phpcs-tests",
2426
"phpunit": "run-php-unit-tests",
25-
"behat": "run-behat-tests",
2627
"prepare-tests": "install-package-tests",
2728
"test": [
2829
"@lint",
@@ -51,7 +52,7 @@ To make use of the WP-CLI testing framework, you need to complete the following
5152
```
5253
This will make sure that the automated Behat system works across all platforms. This is needed on Windows.
5354

54-
4. Update your composer dependencies and regenerate your autoloader and binary folders:
55+
5. Update your composer dependencies and regenerate your autoloader and binary folders:
5556
```bash
5657
composer update
5758
```
@@ -80,6 +81,72 @@ Prepending with the double dash is needed because the arguments would otherwise
8081

8182
### Controlling the test environment
8283

84+
#### WordPress Version
85+
86+
You can run the tests against a specific version of WordPress by setting the `WP_VERSION` environment variable.
87+
88+
This variable understands any numeric version, as well as the special terms `latest` and `trunk`.
89+
90+
Note: This only applies to the Behat functional tests. All other tests never load WordPress.
91+
92+
Here's how to run your tests against the latest trunk version of WordPress:
93+
```bash
94+
WP_VERSION=trunk composer behat
95+
```
96+
97+
#### WP-CLI Binary
98+
99+
You can run the tests against a specific WP-CLI binary, instead of using the one that has been built in your project's `vendor/bin` folder.
100+
101+
This can be useful to run your tests against a specific Phar version of WP_CLI.
102+
103+
To do this, you can set the `WP_CLI_BIN_DIR` environment variable to point to a folder that contains an executable `wp` binary. Note: the binary has to be named `wp` to be properly recognized.
104+
105+
As an example, here's how to run your tests against a specific Phar version you've downloaded.
106+
```bash
107+
# Prepare the binary you've downloaded into the ~/wp-cli folder first.
108+
mv ~/wp-cli/wp-cli-1.2.0.phar ~/wp-cli/wp
109+
chmod +x ~/wp-cli/wp
110+
111+
WP_CLI_BIN_DIR=~/wp-cli composer behat
112+
```
113+
114+
### Setting up the tests in Travis CI
115+
116+
Basic rules for setting up the test framework with Travis CI:
117+
118+
* `composer prepare-tests` needs to be called once per environment.
119+
* `linting and sniffing` is a static analysis, so it shouldn't depend on any specific environment. You should do this only once, as a separate stage, instead of per environment.
120+
* `composer behat || composer behat-rerun` causes the Behat tests to run in their entirety first, and in case their were failed scenarios, a second run is done with only the failed scenarios. This usually gets around intermittent issues like timeouts or similar.
121+
122+
Here's a basic setup of how you can configure Travis CI to work with the test framework (extract):
123+
```yml
124+
install:
125+
- composer install
126+
- composer prepare-tests
127+
128+
script:
129+
- composer phpunit
130+
- composer behat || composer behat-rerun
131+
132+
jobs:
133+
include:
134+
- stage: sniff
135+
script:
136+
- composer lint
137+
- composer phpcs
138+
env: BUILD=sniff
139+
- stage: test
140+
php: 7.2
141+
env: WP_VERSION=latest
142+
- stage: test
143+
php: 7.2
144+
env: WP_VERSION=3.7.11
145+
- stage: test
146+
php: 7.2
147+
env: WP_VERSION=trunk
148+
```
149+
83150
#### WP-CLI version
84151
85152
You can point the tests to a specific version ow WP-CLI through the `WP_CLI_BIN_DIR` constant:

features/bootstrap/FeatureContext.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,9 @@ private static function get_behat_internal_variables() {
209209
}
210210

211211
$variables = [
212-
'SRC_DIR' => realpath( dirname( dirname( __DIR__ ) ) ),
213212
'FRAMEWORK_ROOT' => realpath( $framework_root ),
213+
'SRC_DIR' => realpath( dirname( dirname( __DIR__ ) ) ),
214+
'PROJECT_DIR' => realpath( dirname( dirname( dirname( dirname( dirname( __DIR__ ) ) ) ) ) ),
214215
];
215216

216217
return $variables;

features/steps/given.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ function ( $world, $type = 'subdirectory' ) {
134134
'/^these installed and active plugins:$/',
135135
function( $world, $stream ) {
136136
$plugins = implode( ' ', array_map( 'trim', explode( PHP_EOL, (string) $stream ) ) );
137+
$plugins = $world->replace_variables( $plugins );
138+
137139
$world->proc( "wp plugin install $plugins --activate" )->run_check();
138140
}
139141
);

0 commit comments

Comments
 (0)