Skip to content

Commit 894c765

Browse files
authored
Merge pull request #16 from wp-cli/13-rerun-failed-scenarios
Explain how to re-run failed scenarios
2 parents bf56c6c + 8107b1e commit 894c765

File tree

2 files changed

+104
-22
lines changed

2 files changed

+104
-22
lines changed

.travis.yml

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ sudo: false
22
dist: trusty
33

44
language: php
5+
php: 7.2
56

67
notifications:
78
email:
@@ -21,23 +22,6 @@ env:
2122
- PATH="$TRAVIS_BUILD_DIR/vendor/bin:$PATH"
2223
- WP_CLI_BIN_DIR="$TRAVIS_BUILD_DIR/vendor/bin"
2324

24-
matrix:
25-
include:
26-
- php: 7.2
27-
env: WP_VERSION=latest
28-
- php: 7.1
29-
env: WP_VERSION=latest
30-
- php: 7.0
31-
env: WP_VERSION=latest
32-
- php: 5.6
33-
env: WP_VERSION=latest
34-
- php: 5.6
35-
env: WP_VERSION=3.7.11
36-
- php: 5.6
37-
env: WP_VERSION=trunk
38-
- php: 5.4
39-
env: WP_VERSION=latest
40-
4125
before_install:
4226
- |
4327
# Remove Xdebug for a huge performance increase:
@@ -46,13 +30,45 @@ before_install:
4630
else
4731
echo "xdebug.ini does not exist"
4832
fi
33+
- |
34+
# Raise PHP memory limit to 2048MB
35+
echo 'memory_limit = 2048M' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
36+
- composer validate
4937

5038
install:
5139
- composer install
5240
- composer prepare-tests
5341

54-
before_script:
55-
- composer validate
56-
5742
script:
58-
- composer test
43+
- composer phpunit
44+
- composer behat || composer behat-rerun
45+
46+
jobs:
47+
include:
48+
- stage: sniff
49+
script:
50+
- composer lint
51+
- composer phpcs
52+
env: BUILD=sniff
53+
- stage: test
54+
php: 7.2
55+
env: WP_VERSION=latest
56+
- stage: test
57+
php: 7.1
58+
env: WP_VERSION=latest
59+
- stage: test
60+
php: 7.0
61+
env: WP_VERSION=latest
62+
- stage: test
63+
php: 5.6
64+
env: WP_VERSION=latest
65+
- stage: test
66+
php: 5.6
67+
env: WP_VERSION=3.7.11
68+
- stage: test
69+
php: 5.6
70+
env: WP_VERSION=trunk
71+
- stage: test
72+
php: 5.4
73+
dist: precise
74+
env: WP_VERSION=latest

README.md

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ To make use of the WP-CLI testing framework, you need to complete the following
5252
```
5353
This will make sure that the automated Behat system works across all platforms. This is needed on Windows.
5454

55-
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:
5656
```bash
5757
composer update
5858
```
@@ -81,6 +81,72 @@ Prepending with the double dash is needed because the arguments would otherwise
8181

8282
### Controlling the test environment
8383

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+
84150
#### WP-CLI version
85151
86152
You can point the tests to a specific version ow WP-CLI through the `WP_CLI_BIN_DIR` constant:

0 commit comments

Comments
 (0)