11#! /bin/sh
22
33# Database credentials can be provided via environment variables:
4- # - WP_CLI_TEST_DBHOST is the host to use and can include a port, i.e "127.0.0.1:33060" (defaults to "localhost")
4+ # - WP_CLI_TEST_DBHOST is the host to use and can include a port or a socket after a colon , i.e "127.0.0.1:33060" (defaults to "localhost")
55# - WP_CLI_TEST_DBROOTUSER is the user that has permission to administer databases and users (defaults to "root").
66# - WP_CLI_TEST_DBROOTPASS is the password to use for the above user (defaults to an empty password).
77# - WP_CLI_TEST_DBNAME is the database that the tests run under (defaults to "wp_cli_test").
88# - WP_CLI_TEST_DBUSER is the user that the tests run under (defaults to "wp_cli_test").
99# - WP_CLI_TEST_DBPASS is the password to use for the above user (defaults to "password1").
1010
11+ # POSIX compliant function to check if a string is numeric.
12+ is_numeric () {
13+ case $1 in
14+ ' ' |* [!0-9]* ) return 1;; # returns 1 if not numeric
15+ * ) return 0;; # returns 0 if numeric
16+ esac
17+ }
18+
1119HOST=localhost
1220PORT=" "
1321HOST_STRING=' '
@@ -16,9 +24,14 @@ if [ -n "${WP_CLI_TEST_DBHOST}" ]; then
1624 (* :* ) HOST=${WP_CLI_TEST_DBHOST%:* } PORT=${WP_CLI_TEST_DBHOST##*: } ;;
1725 (* ) HOST=${WP_CLI_TEST_DBHOST} ;;
1826 esac
19- HOST_STRING=" -h${HOST} "
20- if [ -n " ${PORT} " ]; then
21- HOST_STRING=" ${HOST_STRING} -P${PORT} --protocol=tcp"
27+ HOST_STRING=" -h${HOST} "
28+ if [ -n " ${PORT} " ]; then
29+ # If the port is not numeric, then we assume it is a socket path.
30+ if is_numeric " ${PORT} " ; then
31+ HOST_STRING=" ${HOST_STRING} -P${PORT} --protocol=tcp"
32+ else
33+ HOST_STRING=" ${HOST_STRING} --socket=${PORT} "
34+ fi
2235 fi
2336fi
2437
0 commit comments