From 6b4fc92789ea99f356ce150b5c5159353ad58e9b Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sun, 23 Nov 2025 22:33:13 +0100 Subject: [PATCH 1/2] Fall back to running tests with SQLite --- bin/run-behat-tests | 70 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/bin/run-behat-tests b/bin/run-behat-tests index f9a09bc15..a2d667217 100755 --- a/bin/run-behat-tests +++ b/bin/run-behat-tests @@ -19,6 +19,76 @@ if [[ "$@" == *"--help"* ]]; then exit $ret fi +# POSIX compliant function to check if a string is numeric. +is_numeric() { + case $1 in + ''|*[!0-9]*) return 1;; # returns 1 if not numeric + *) return 0;; # returns 0 if numeric + esac +} + +# If DB type is already set to SQLite, there's nothing to do. +if [ "${WP_CLI_TEST_DBTYPE-}" = "sqlite" ]; then + echo "WP_CLI_TEST_DBTYPE is set to 'sqlite', skipping database check." +else + # Check for database client and connectivity. + DB_CLIENT="" + if command -v mysql &> /dev/null; then + DB_CLIENT="mysql" + elif command -v mariadb &> /dev/null; then + DB_CLIENT="mariadb" + fi + + if [ -z "${DB_CLIENT}" ]; then + echo "Warning: Could not find 'mysql' or 'mariadb' client." + echo "The tests will continue to be run, but with WP_CLI_TEST_DBTYPE=sqlite." + export WP_CLI_TEST_DBTYPE=sqlite + else + HOST_STRING='' + if [ -n "${WP_CLI_TEST_DBHOST}" ]; then + case ${WP_CLI_TEST_DBHOST##*[]]} in + (*:*) HOST=${WP_CLI_TEST_DBHOST%:*} PORT=${WP_CLI_TEST_DBHOST##*:};; + (*) HOST=${WP_CLI_TEST_DBHOST};; + esac + HOST_STRING="-h${HOST}" + if [ -n "${PORT}" ]; then + # If the port is not numeric, then we assume it is a socket path. + if is_numeric "${PORT}"; then + HOST_STRING="${HOST_STRING} --port=${PORT} --protocol=tcp" + else + HOST_STRING="${HOST_STRING} --socket=${PORT} --protocol=socket" + fi + fi + fi + + USER=${WP_CLI_TEST_DBUSER:-wp_cli_test} + + if [ -z "${WP_CLI_TEST_DBPASS+x}" ]; then + # not set, use default + PASSWORD="password1" + else + # is set, use its value (could be empty) + PASSWORD="${WP_CLI_TEST_DBPASS}" + fi + + PASSWORD_ARG="" + if [ -n "${PASSWORD}" ]; then + PASSWORD_ARG="-p${PASSWORD}" + fi + + DBNAME=${WP_CLI_TEST_DBNAME:-wp_cli_test} + + # We need to test the connection. + # Let's try to connect to the specific test database. + if ! ${DB_CLIENT} ${HOST_STRING} --user="${USER}" ${PASSWORD_ARG} --execute="USE \`${DBNAME}\`;" 2>/dev/null; then + echo "Warning: Could not connect to the MySQL/MariaDB database." + echo "Please make sure the database is running and run 'composer prepare-tests' once to set it up." + echo "The tests will continue to be run, but with WP_CLI_TEST_DBTYPE=sqlite." + export WP_CLI_TEST_DBTYPE=sqlite + fi + fi +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") From 240a89e283b6ef1777cdc9351e6633446ce2164f Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sun, 23 Nov 2025 22:42:06 +0100 Subject: [PATCH 2/2] fix tabs vs spaces --- bin/run-behat-tests | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/bin/run-behat-tests b/bin/run-behat-tests index a2d667217..a64df53a8 100755 --- a/bin/run-behat-tests +++ b/bin/run-behat-tests @@ -3,28 +3,28 @@ # 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; + exit 0; fi if ! command -v jq &> /dev/null then - echo 'The required "jq" command was not found, please install it to run the Behat tests.' - echo "See https://stedolan.github.io/jq/download/ for installation instructions." - exit 1; + echo 'The required "jq" command was not found, please install it to run the Behat tests.' + echo "See https://stedolan.github.io/jq/download/ for installation instructions." + exit 1; fi if [[ "$@" == *"--help"* ]]; then - vendor/bin/behat "$@" - ret=$? - exit $ret + vendor/bin/behat "$@" + ret=$? + exit $ret fi # POSIX compliant function to check if a string is numeric. is_numeric() { - case $1 in - ''|*[!0-9]*) return 1;; # returns 1 if not numeric - *) return 0;; # returns 0 if numeric - esac + case $1 in + ''|*[!0-9]*) return 1;; # returns 1 if not numeric + *) return 0;; # returns 0 if numeric + esac } # If DB type is already set to SQLite, there's nothing to do. @@ -100,11 +100,11 @@ SOURCE="${BASH_SOURCE[0]}" # 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. - [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" + 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. + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" done # Fetch the root folder of the WP-CLI tests package.