Skip to content

Commit

Permalink
Merge pull request #138 from wp-cli/fix/126-check-behat-config
Browse files Browse the repository at this point in the history
  • Loading branch information
schlessera authored Nov 23, 2021
2 parents 79d0a53 + 043d2b9 commit bd8e26d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 44 deletions.
33 changes: 8 additions & 25 deletions bin/rerun-behat-tests
Original file line number Diff line number Diff line change
@@ -1,37 +1,20 @@
#!/bin/bash

# Run the Behat tests only if a features folder exists
if [ ! -d "features" ]; then
exit 0;
fi

# Turn WP_VERSION into an actual number to make sure our tags work correctly.
if [ "${WP_VERSION-latest}" = "latest" ]; then
export WP_VERSION=$(curl -s https://api.wordpress.org/core/version-check/1.7/ | jq -r ".offers[0].current")
fi

# To retrieve the Behat root folder, we start with this scripts location
# To retrieve the WP-CLI tests package root folder, we start with this scripts
# location.
SOURCE="${BASH_SOURCE[0]}"

# Resolve $SOURCE until the file is no longer a symlink
# Resolve $SOURCE until the file is no longer a symlink.
while [ -h "$SOURCE" ]; do
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
# If $SOURCE was a relative symlink, we need to resolve it relative to the
# path where the symlink file was located
# path where the symlink file was located.
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done

# Fetch the root folder of the Behat package
BEHAT_ROOT="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
export BEHAT_ROOT

# Set Behat environment variables
BEHAT_PARAMS="{\"suites\":{\"default\":{\"contexts\":[\"WP_CLI\\\\Tests\\\\Context\\\\FeatureContext\"],\"paths\":[\"features\"]}}}"
export BEHAT_PARAMS

# Generate the tags to apply environment-specific filters
BEHAT_TAGS=$(php "$BEHAT_ROOT"/utils/behat-tags.php)
# Fetch the root folder of the WP-CLI tests package.
WP_CLI_TESTS_ROOT="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
export WP_CLI_TESTS_ROOT

# Run the functional tests
vendor/bin/behat --format progress "$BEHAT_TAGS" --strict --rerun "$@"
"$WP_CLI_TESTS_ROOT"/bin/run-behat-tests --rerun "$@"
33 changes: 14 additions & 19 deletions bin/run-behat-tests
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

# Run the Behat tests only if a features folder exists
if [ ! -d "features" ]; then
echo 'Did not detect "features" directory, skipping Behat tests.'
# Run the Behat tests only if a Behat config file is found.
if [ ! -f "behat.yml" ]; then
echo 'Did not detect "behat.yml" file, skipping Behat tests.'
exit 0;
fi

Expand All @@ -13,35 +13,30 @@ then
exit 1;
fi

rm -f ".behat-progress.log"

# Turn WP_VERSION into an actual number to make sure our tags work correctly.
if [ "${WP_VERSION-latest}" = "latest" ]; then
export WP_VERSION=$(curl -s https://api.wordpress.org/core/version-check/1.7/ | jq -r ".offers[0].current")
fi

# To retrieve the Behat root folder, we start with this scripts location
# To retrieve the WP-CLI tests package root folder, we start with this scripts
# location.
SOURCE="${BASH_SOURCE[0]}"

# Resolve $SOURCE until the file is no longer a symlink
# Resolve $SOURCE until the file is no longer a symlink.
while [ -h "$SOURCE" ]; do
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
# If $SOURCE was a relative symlink, we need to resolve it relative to the
# path where the symlink file was located
# path where the symlink file was located.
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done

# Fetch the root folder of the Behat package
BEHAT_ROOT="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
export BEHAT_ROOT

# Set Behat environment variables
BEHAT_PARAMS="{\"suites\":{\"default\":{\"contexts\":[\"WP_CLI\\\\Tests\\\\Context\\\\FeatureContext\"],\"paths\":[\"features\"]}}}"
export BEHAT_PARAMS
# Fetch the root folder of the WP-CLI tests package.
WP_CLI_TESTS_ROOT="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
export WP_CLI_TESTS_ROOT

# Generate the tags to apply environment-specific filters
BEHAT_TAGS=$(php "$BEHAT_ROOT"/utils/behat-tags.php)
# Generate the tags to apply environment-specific filters.
BEHAT_TAGS=$(php "$WP_CLI_TESTS_ROOT"/utils/behat-tags.php)

# Run the functional tests
vendor/bin/behat --format progress "$BEHAT_TAGS" --strict --rerun "$@"
# Run the functional tests.
vendor/bin/behat --format progress "$BEHAT_TAGS" --strict "$@"

0 comments on commit bd8e26d

Please sign in to comment.