Skip to content

Commit 8543fbe

Browse files
Retool Travis to provide same level of coverage with less builds
1 parent a7d0348 commit 8543fbe

File tree

2 files changed

+156
-37
lines changed

2 files changed

+156
-37
lines changed

.travis.yml

+36-37
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,46 @@ sudo: false
22

33
language: php
44

5-
php:
6-
- 5.3
7-
- 5.4
8-
- 5.5
9-
- 5.6
10-
11-
env:
12-
- WP_VERSION=master WP_MULTISITE=0
13-
- WP_VERSION=master WP_MULTISITE=1
14-
- WP_VERSION=4.4 WP_MULTISITE=0
15-
- WP_VERSION=4.4 WP_MULTISITE=1
16-
- WP_VERSION=4.3 WP_MULTISITE=0
17-
- WP_VERSION=4.3 WP_MULTISITE=1
18-
195
matrix:
20-
include:
21-
- php: 7.0
22-
env: WP_VERSION=master
23-
allow_failures:
24-
- php: 7.0
25-
fast_finish: true
6+
include:
7+
- php: 5.3
8+
env: WP_VERSION=latest
9+
- php: 5.6
10+
env: WP_VERSION=latest
11+
- php: 7.0
12+
env: WP_VERSION=latest
13+
- php: 5.6
14+
env: WP_VERSION=nightly
15+
- php: 5.6
16+
env: WP_TRAVISCI=phpcs
17+
allow_failures:
18+
- php: 7.0
19+
fast_finish: true
2620

2721
branches:
28-
only:
29-
- master
22+
only:
23+
- master
3024

3125
before_script:
32-
- export WP_TESTS_DIR=/tmp/wordpress/tests/phpunit
33-
- export WP_CORE_DIR=/tmp/wordpress/src/
34-
- git clone --depth=50 --branch="$WP_VERSION" git://develop.git.wordpress.org/ /tmp/wordpress
35-
- mysql -e "CREATE DATABASE wordpress_tests;" -uroot
36-
- cp /tmp/wordpress/wp-tests-config-sample.php /tmp/wordpress/wp-tests-config.php
37-
- sed -i "s/youremptytestdbnamehere/wordpress_tests/" /tmp/wordpress/wp-tests-config.php
38-
- sed -i "s/yourusernamehere/travis/" /tmp/wordpress/wp-tests-config.php
39-
- sed -i "s/yourpasswordhere//" /tmp/wordpress/wp-tests-config.php
40-
- npm install -g npm
41-
- npm install -g grunt-cli
42-
- npm install
43-
- composer install
26+
- |
27+
if [[ ! -z "$WP_VERSION" ]] ; then
28+
bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
29+
npm install
30+
fi
31+
- |
32+
if [[ "$WP_TRAVISCI" == "phpcs" ]] ; then
33+
npm install
34+
composer install
35+
fi
4436
4537
script:
46-
- phpunit
47-
- grunt qunit:specific --wp=$WP_VERSION
48-
- grunt phpcs
38+
- |
39+
if [[ ! -z "$WP_VERSION" ]] ; then
40+
phpunit
41+
phpunit -c multisite.xml
42+
grunt qunit:specific --wp=$WP_VERSION
43+
fi
44+
- |
45+
if [[ "$WP_TRAVISCI" == "phpcs" ]] ; then
46+
grunt phpcs
47+
fi

bin/install-wp-tests.sh

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#!/usr/bin/env bash
2+
3+
if [ $# -lt 3 ]; then
4+
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version]"
5+
exit 1
6+
fi
7+
8+
DB_NAME=$1
9+
DB_USER=$2
10+
DB_PASS=$3
11+
DB_HOST=${4-localhost}
12+
WP_VERSION=${5-latest}
13+
14+
WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib}
15+
WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/}
16+
17+
download() {
18+
if [ `which curl` ]; then
19+
curl -s "$1" > "$2";
20+
elif [ `which wget` ]; then
21+
wget -nv -O "$2" "$1"
22+
fi
23+
}
24+
25+
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+(\.[0-9]+)? ]]; then
26+
WP_TESTS_TAG="tags/$WP_VERSION"
27+
elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
28+
WP_TESTS_TAG="trunk"
29+
else
30+
# http serves a single offer, whereas https serves multiple. we only want one
31+
download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
32+
grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json
33+
LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//')
34+
if [[ -z "$LATEST_VERSION" ]]; then
35+
echo "Latest WordPress version could not be found"
36+
exit 1
37+
fi
38+
WP_TESTS_TAG="tags/$LATEST_VERSION"
39+
fi
40+
41+
set -ex
42+
43+
install_wp() {
44+
45+
if [ -d $WP_CORE_DIR ]; then
46+
return;
47+
fi
48+
49+
mkdir -p $WP_CORE_DIR
50+
51+
if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
52+
mkdir -p /tmp/wordpress-nightly
53+
download https://wordpress.org/nightly-builds/wordpress-latest.zip /tmp/wordpress-nightly/wordpress-nightly.zip
54+
unzip -q /tmp/wordpress-nightly/wordpress-nightly.zip -d /tmp/wordpress-nightly/
55+
mv /tmp/wordpress-nightly/wordpress/* $WP_CORE_DIR
56+
else
57+
if [ $WP_VERSION == 'latest' ]; then
58+
local ARCHIVE_NAME='latest'
59+
else
60+
local ARCHIVE_NAME="wordpress-$WP_VERSION"
61+
fi
62+
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz
63+
tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
64+
fi
65+
66+
download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
67+
}
68+
69+
install_test_suite() {
70+
# portable in-place argument for both GNU sed and Mac OSX sed
71+
if [[ $(uname -s) == 'Darwin' ]]; then
72+
local ioption='-i .bak'
73+
else
74+
local ioption='-i'
75+
fi
76+
77+
# set up testing suite if it doesn't yet exist
78+
if [ ! -d $WP_TESTS_DIR ]; then
79+
# set up testing suite
80+
mkdir -p $WP_TESTS_DIR
81+
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
82+
fi
83+
84+
cd $WP_TESTS_DIR
85+
86+
if [ ! -f wp-tests-config.php ]; then
87+
download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
88+
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" "$WP_TESTS_DIR"/wp-tests-config.php
89+
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
90+
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
91+
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
92+
sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
93+
fi
94+
95+
}
96+
97+
install_db() {
98+
# parse DB_HOST for port or socket references
99+
local PARTS=(${DB_HOST//\:/ })
100+
local DB_HOSTNAME=${PARTS[0]};
101+
local DB_SOCK_OR_PORT=${PARTS[1]};
102+
local EXTRA=""
103+
104+
if ! [ -z $DB_HOSTNAME ] ; then
105+
if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
106+
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
107+
elif ! [ -z $DB_SOCK_OR_PORT ] ; then
108+
EXTRA=" --socket=$DB_SOCK_OR_PORT"
109+
elif ! [ -z $DB_HOSTNAME ] ; then
110+
EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
111+
fi
112+
fi
113+
114+
# create database
115+
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
116+
}
117+
118+
install_wp
119+
install_test_suite
120+
install_db

0 commit comments

Comments
 (0)