Skip to content

Commit

Permalink
Merge pull request #844 from 10up/fix/unit-tests
Browse files Browse the repository at this point in the history
Switch PHPUnit test install script to use `git` instead of `svn`
  • Loading branch information
dkotter authored Jan 24, 2025
2 parents 57d27bd + 25c0baf commit c13143e
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions bin/install-wp-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,19 @@ WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib}
WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/}

download() {
if [ `which curl` ]; then
curl -s "$1" > "$2";
elif [ `which wget` ]; then
wget -nv -O "$2" "$1"
fi
if [ `which curl` ]; then
curl -s "$1" > "$2";
elif [ `which wget` ]; then
wget -nv -O "$2" "$1"
fi
}

# Check if git is installed
check_git_installed() {
if ! command -v git > /dev/null; then
echo "Error: git is not installed. Please install git and try again."
exit 1
fi
}

if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+$ ]]; then
Expand All @@ -35,6 +43,7 @@ elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then
WP_TESTS_TAG="tags/$WP_VERSION"
fi
elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
WP_BRANCH="trunk"
WP_TESTS_TAG="trunk"
else
# http serves a single offer, whereas https serves multiple. we only want one
Expand All @@ -45,6 +54,7 @@ else
echo "Latest WordPress version could not be found"
exit 1
fi
WP_BRANCH=$LATEST_VERSION
WP_TESTS_TAG="tags/$LATEST_VERSION"
fi

Expand Down Expand Up @@ -104,12 +114,16 @@ install_test_suite() {
if [ ! -d $WP_TESTS_DIR ]; then
# set up testing suite
mkdir -p $WP_TESTS_DIR
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data
check_git_installed
git clone --depth 1 --branch $WP_BRANCH https://github.com/wordpress/wordpress-develop $TMPDIR/wordpress-develop
rm -r $TMPDIR/wordpress-develop/.git
mv $TMPDIR/wordpress-develop/tests/phpunit/includes/ $WP_TESTS_DIR/includes
mv $TMPDIR/wordpress-develop/tests/phpunit/data/ $WP_TESTS_DIR/data
rm -r $TMPDIR/wordpress-develop
fi

if [ ! -f wp-tests-config.php ]; then
download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
download https://raw.githubusercontent.com/wordpress/wordpress-develop/${WP_BRANCH}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
# remove all forward slashes in the end
WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::")
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php
Expand Down Expand Up @@ -144,12 +158,12 @@ install_db() {
fi

# create database
if [ -z $DB_PASS ] ; then
echo 'No DB password'
mysqladmin create $DB_NAME --user="$DB_USER" $EXTRA
else
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
fi
if [ -z $DB_PASS ] ; then
echo 'No DB password'
mysqladmin create $DB_NAME --user="$DB_USER" $EXTRA
else
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
fi
}

install_wp
Expand Down

0 comments on commit c13143e

Please sign in to comment.