Skip to content

Commit bf56c6c

Browse files
authored
Merge pull request #15 from wp-cli/12-automated-rerun-support
Add rerun-behat-tests command
2 parents a0add83 + ba39c69 commit bf56c6c

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
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",

bin/rerun-behat-tests

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
# Run the Behat tests only if a features folder exists
4+
if [ ! -d "features" ]; then
5+
exit 0;
6+
fi
7+
8+
# Turn WP_VERSION into an actual number to make sure our tags work correctly.
9+
if [ "${WP_VERSION-latest}" = "latest" ]; then
10+
export WP_VERSION=$(curl -s https://api.wordpress.org/core/version-check/1.7/ | jq -r ".offers[0].current")
11+
fi
12+
13+
# To retrieve the Behat root folder, we start with this scripts location
14+
SOURCE="${BASH_SOURCE[0]}"
15+
16+
# Resolve $SOURCE until the file is no longer a symlink
17+
while [ -h "$SOURCE" ]; do
18+
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
19+
SOURCE="$(readlink "$SOURCE")"
20+
# If $SOURCE was a relative symlink, we need to resolve it relative to the
21+
# path where the symlink file was located
22+
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
23+
done
24+
25+
# Fetch the root folder of the Behat package
26+
BEHAT_ROOT="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
27+
export BEHAT_ROOT
28+
29+
# Set Behat environment variables
30+
BEHAT_PARAMS="paths[bootstrap]=$(php -r "echo urlencode('$BEHAT_ROOT/features/bootstrap');")"
31+
export BEHAT_PARAMS
32+
33+
# Generate the tags to apply environment-specific filters
34+
BEHAT_TAGS=$(php "$BEHAT_ROOT"/utils/behat-tags.php)
35+
36+
# Run the functional tests
37+
vendor/bin/behat --format progress "$BEHAT_TAGS" --strict --ansi --rerun=".behat-progress.log" "$@"

bin/run-behat-tests

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ if [ ! -d "features" ]; then
55
exit 0;
66
fi
77

8+
rm -f ".behat-progress.log"
9+
810
# Turn WP_VERSION into an actual number to make sure our tags work correctly.
911
if [ "${WP_VERSION-latest}" = "latest" ]; then
1012
export WP_VERSION=$(curl -s https://api.wordpress.org/core/version-check/1.7/ | jq -r ".offers[0].current")
@@ -34,4 +36,4 @@ export BEHAT_PARAMS
3436
BEHAT_TAGS=$(php "$BEHAT_ROOT"/utils/behat-tags.php)
3537

3638
# Run the functional tests
37-
vendor/bin/behat --format progress "$BEHAT_TAGS" --strict --ansi "$@"
39+
vendor/bin/behat --format progress "$BEHAT_TAGS" --strict --ansi --rerun=".behat-progress.log" "$@"

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@
4848
"prefer-stable": true,
4949
"bin": [
5050
"bin/install-package-tests",
51+
"bin/rerun-behat-tests",
5152
"bin/run-behat-tests",
5253
"bin/run-linter-tests",
5354
"bin/run-php-unit-tests",
5455
"bin/run-phpcs-tests"
5556
],
5657
"scripts": {
5758
"behat": "run-behat-tests",
59+
"behat-rerun": "rerun-behat-tests",
5860
"lint": "run-linter-tests",
5961
"phpcs": "run-phpcs-tests",
6062
"phpunit": "run-php-unit-tests",

0 commit comments

Comments
 (0)