Skip to content

Commit

Permalink
check if the database exists before running redis-enabled tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jazzsequence committed Oct 12, 2023
1 parent 3734f5c commit e84fb13
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion bin/phpunit-redis-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,25 @@ set -e

DIRNAME=$(dirname "$0")

bash "${DIRNAME}/install-wp-tests.sh" wordpress_test root root 127.0.0.1 latest
WITHDB="true"

function database_exists {
# Usage: database_exists <database_name> <user> <password> <host>
local dbname=$1
local dbuser=$2
local dbpass=$3
local dbhost=$4
echo "SHOW DATABASES LIKE '${dbname}';" | mysql -u"${dbuser}" -p"${dbpass}" -h"${dbhost}" 2>/dev/null | grep "${dbname}" > /dev/null
return $?
}

# Check if the database exists
if database_exists wordpress_test root root 127.0.0.1; then
echo "Database wordpress_test already exists, we won't install a new one..."
WITHDB=""
fi

bash "${DIRNAME}/install-wp-tests.sh" wordpress_test root root 127.0.0.1 latest "$WITHDB"
echo "Running WP Redis PHPUnit Tests on Single Site"
WP_REDIS_USE_CACHE_GROUPS=1 composer phpunit
rm -rf "$WP_TESTS_DIR" "$WP_CORE_DIR"
Expand Down

0 comments on commit e84fb13

Please sign in to comment.