diff --git a/tests/bin/install.sh b/tests/bin/install.sh index 1fde8470591..0864ac1987e 100755 --- a/tests/bin/install.sh +++ b/tests/bin/install.sh @@ -128,24 +128,22 @@ install_db() { return 0 fi - # parse DB_HOST for port or socket references - local PARTS=(${DB_HOST//\:/ }) - local DB_HOSTNAME=${PARTS[0]}; - local DB_SOCK_OR_PORT=${PARTS[1]}; - local EXTRA="" - - if ! [ -z $DB_HOSTNAME ] ; then - if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then - EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp" - elif ! [ -z $DB_SOCK_OR_PORT ] ; then - EXTRA=" --socket=$DB_SOCK_OR_PORT" - elif ! [ -z $DB_HOSTNAME ] ; then - EXTRA=" --host=$DB_HOSTNAME --protocol=tcp" + # If we're trying to connect to a socket we want to handle it differently. + if [[ "$DB_HOST" == *.sock ]]; then + # create database using the socket + mysqladmin create $DB_NAME --socket="$DB_HOST" + else + # Decide whether or not there is a port. + local PARTS=(${DB_HOST//\:/ }) + if [[ ${PARTS[1]} =~ ^[0-9]+$ ]]; then + EXTRA=" --host=${PARTS[0]} --port=${PARTS[1]} --protocol=tcp" + else + EXTRA=" --host=$DB_HOST --protocol=tcp" fi - fi - # create database - mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA + # create database + mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA + fi } install_wp diff --git a/tests/bootstrap.php b/tests/bootstrap.php index ad53b3f48a0..0567482dfd8 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -42,7 +42,7 @@ class WC_Unit_Tests_Bootstrap { $this->tests_dir = dirname( __FILE__ ); $this->plugin_dir = dirname( $this->tests_dir ); - $this->wp_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : '/tmp/wordpress-tests-lib'; + $this->wp_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : sys_get_temp_dir() . '/wordpress-tests-lib'; // load test function so tests_add_filter() is available. require_once $this->wp_tests_dir . '/includes/functions.php'; diff --git a/tests/includes/listener-loader.php b/tests/includes/listener-loader.php index 3ce669c6b48..0218c2b7292 100644 --- a/tests/includes/listener-loader.php +++ b/tests/includes/listener-loader.php @@ -5,5 +5,5 @@ * @package WooCommerce\UnitTests */ -$wp_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : '/tmp/wordpress-tests-lib'; +$wp_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : sys_get_temp_dir() . '/wordpress-tests-lib'; require_once $wp_tests_dir . '/includes/listener-loader.php'; diff --git a/tests/unit-tests/integrations/maxmind-geolocation/class-wc-tests-maxmind-database.php b/tests/unit-tests/integrations/maxmind-geolocation/class-wc-tests-maxmind-database.php index aba5a35a1af..e4018d93824 100644 --- a/tests/unit-tests/integrations/maxmind-geolocation/class-wc-tests-maxmind-database.php +++ b/tests/unit-tests/integrations/maxmind-geolocation/class-wc-tests-maxmind-database.php @@ -55,7 +55,7 @@ class WC_Tests_MaxMind_Database extends WC_Unit_Test_Case { */ public function test_download_database_works() { $database_service = new WC_Integration_MaxMind_Database_Service( '' ); - $expected_database = '/tmp/GeoLite2-Country_20200100/GeoLite2-Country.mmdb'; + $expected_database = sys_get_temp_dir() . '/GeoLite2-Country_20200100/GeoLite2-Country.mmdb'; $result = $database_service->download_database( 'testing_license' );