Skip to content

Commit

Permalink
Support sockets in compsoer prepare-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
schlessera committed Dec 18, 2023
1 parent 0601666 commit 53bab39
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions bin/install-package-tests
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
# - WP_CLI_TEST_DBUSER is the user that the tests run under (defaults to "wp_cli_test").
# - WP_CLI_TEST_DBPASS is the password to use for the above user (defaults to "password1").

# 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
}

HOST=localhost
PORT=""
HOST_STRING=''
Expand All @@ -16,9 +24,14 @@ if [ -n "${WP_CLI_TEST_DBHOST}" ]; then
(*:*) HOST=${WP_CLI_TEST_DBHOST%:*} PORT=${WP_CLI_TEST_DBHOST##*:};;
(*) HOST=${WP_CLI_TEST_DBHOST};;
esac
HOST_STRING="-h${HOST}"
if [ -n "${PORT}" ]; then
HOST_STRING="${HOST_STRING} -P${PORT} --protocol=tcp"
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} -P${PORT} --protocol=tcp"
else
HOST_STRING="${HOST_STRING} --socket=${PORT}"
fi
fi
fi

Expand Down

0 comments on commit 53bab39

Please sign in to comment.