Skip to content

Commit 3c34274

Browse files
authored
Install PHP5.2/5.3 on trusty for unit tests (#2049)
Uses the SWITCH_TO_PHP environment variable to request older versions of PHP. PHP5.3 and PHP5.2 are installed for the user, using phpbrew. The correct version of PHPUnit is also installed. ~/.phpbrew contains the built PHP versions, and this is cached.
1 parent 73d1410 commit 3c34274

File tree

5 files changed

+240
-11
lines changed

5 files changed

+240
-11
lines changed

.travis.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ cache:
1212
directories:
1313
- vendor
1414
- $HOME/.composer/cache
15+
- $HOME/.phpbrew
1516

1617
before_install:
1718
- nvm install 6.11.1 && nvm use 6.11.1
@@ -23,9 +24,10 @@ matrix:
2324
env: WP_VERSION=latest
2425
- php: 5.6
2526
env: WP_VERSION=latest
26-
- php: 5.2
27-
env: WP_VERSION=latest
28-
dist: precise
27+
- php: 7.1
28+
env: WP_VERSION=latest SWITCH_TO_PHP=5.3
29+
- php: 7.1
30+
env: WP_VERSION=latest SWITCH_TO_PHP=5.2
2931
- php: 5.6
3032
env: TRAVISCI=phpcs
3133
- php: 7.1
@@ -35,15 +37,10 @@ before_script:
3537
- export PATH="$HOME/.composer/vendor/bin:$PATH"
3638
- |
3739
if [[ ! -z "$WP_VERSION" ]] ; then
40+
set -e
3841
bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
39-
if [[ ${TRAVIS_PHP_VERSION:0:2} == "5." ]]; then
40-
mkdir -p $HOME/phpunit-bin
41-
wget -O $HOME/phpunit-bin/phpunit https://phar.phpunit.de/phpunit-4.8.phar
42-
chmod +x $HOME/phpunit-bin/phpunit
43-
export PATH=$PATH:$HOME/phpunit-bin/
44-
else
45-
composer global require "phpunit/phpunit=5.7.*"
46-
fi
42+
source bin/install-php-phpunit.sh
43+
set +e
4744
fi
4845
- |
4946
if [[ "$TRAVISCI" == "phpcs" ]] ; then
@@ -66,6 +63,9 @@ script:
6663
sleep .2 # Otherwise Travis doesn't want to print the whole message
6764
exit 1
6865
fi
66+
echo Running with the following versions:
67+
php -v
68+
phpunit -v
6969
# Check parser syntax
7070
php lib/parser.php || exit 1
7171
# Run PHPUnit tests

bin/install-php-phpunit.sh

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#!/bin/bash
2+
3+
# Uses phpbrew to install older php versions on modern(ish) distros.
4+
# Installs the correct version of phpunit for the requested php
5+
# version. ~/.phpbrew is expected to be cached so we only have
6+
# to build php the first time.
7+
8+
# we have to save and restore the original working directory, because
9+
# phpbrew can mess up if we don't run it from the home directory
10+
ORIG_DIR=`pwd`;
11+
THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
12+
PHP52_PATH=$HOME/.phpbrew/php/php-5.2.17
13+
14+
# install phpunit
15+
16+
mkdir -p $HOME/phpunit-bin
17+
18+
if [[ ${SWITCH_TO_PHP:0:3} == "5.2" ]]; then
19+
# use the phpunit in the PHP5.2 installation
20+
ln -s ${PHP52_PATH}/lib/php/phpunit/phpunit.php $HOME/phpunit-bin/phpunit
21+
elif [[ ${TRAVIS_PHP_VERSION:0:2} == "5." ]] || [[ ${SWITCH_TO_PHP:0:2} == "5." ]]; then
22+
wget -O $HOME/phpunit-bin/phpunit https://phar.phpunit.de/phpunit-4.8.phar
23+
chmod +x $HOME/phpunit-bin/phpunit
24+
else
25+
composer global require "phpunit/phpunit=6.*"
26+
fi
27+
28+
export PATH=$HOME/phpunit-bin/:$PATH
29+
30+
if [[ ${SWITCH_TO_PHP:0:3} == "5.2" ]] || [[ ${SWITCH_TO_PHP:0:3} == "5.3" ]]; then
31+
PHPBREW_BUILT_CHECK=$HOME/.phpbrew/bashrc
32+
33+
# directory to store phpbrew and old phpunit in
34+
mkdir -p $HOME/php-utils-bin
35+
36+
# install phpbrew
37+
curl -L -o $HOME/php-utils-bin/phpbrew https://github.com/phpbrew/phpbrew/raw/f6a422e1ba49293ee73bc4c317795c021bc57020/phpbrew
38+
chmod +x $HOME/php-utils-bin/phpbrew
39+
40+
# needs to be on the path for switching php versions to work
41+
export PATH=$HOME/php-utils-bin:$PATH
42+
43+
# php and phpunit3.6 installs should be cached, only build if they're not there.
44+
if [ ! -f $PHPBREW_BUILT_CHECK ]; then
45+
46+
# init with known --old to get 5.2 and 5.3
47+
$HOME/php-utils-bin/phpbrew init
48+
$HOME/php-utils-bin/phpbrew known --old
49+
50+
# build PHP5.2
51+
tail -F $HOME/.phpbrew/build/php-5.2.17/build.log &
52+
TAIL_PID=$!
53+
$HOME/php-utils-bin/phpbrew install --patch ${THIS_DIR}/patches/node.patch --patch ${THIS_DIR}/patches/openssl.patch 5.2 +default +mysql +pdo \
54+
+gettext +phar +openssl -- --with-openssl-dir=/usr/include/openssl --enable-spl --with-mysql --with-mysqli=/usr/bin/mysql_config --with-pdo-mysql=/usr
55+
kill -TERM $TAIL_PID
56+
57+
# build PHP5.3
58+
tail -F $HOME/.phpbrew/build/php-5.3.29/build.log &
59+
TAIL_PID=$!
60+
$HOME/php-utils-bin/phpbrew install --patch ${THIS_DIR}/patches/node.patch --patch ${THIS_DIR}/patches/openssl.patch 5.3 +default +mysql +pdo \
61+
+gettext +phar +openssl -- --with-openssl-dir=/usr/include/openssl --enable-spl --with-mysql --with-mysqli=/usr/bin/mysql_config --with-pdo-mysql=/usr
62+
kill -TERM $TAIL_PID
63+
64+
# install PHPUnit 3.6. The only install method available is from source, using git branches old
65+
# enough that they don't rely on any PHP5.3+ features. This clones each needed dependency
66+
# and then we add the paths to the include_path by setting up an extra .ini file
67+
cd ${PHP52_PATH}/lib/php
68+
69+
# dependencies
70+
git clone --depth=1 --branch=1.1 git://github.com/sebastianbergmann/dbunit.git
71+
git clone --depth=1 --branch=1.1 git://github.com/sebastianbergmann/php-code-coverage.git
72+
git clone --depth=1 --branch=1.3.2 git://github.com/sebastianbergmann/php-file-iterator.git
73+
git clone --depth=1 --branch=1.1.1 git://github.com/sebastianbergmann/php-invoker.git
74+
git clone --depth=1 --branch=1.1.2 git://github.com/sebastianbergmann/php-text-template.git
75+
git clone --depth=1 --branch=1.0.3 git://github.com/sebastianbergmann/php-timer.git
76+
git clone --depth=1 --branch=1.1.4 git://github.com/sebastianbergmann/php-token-stream.git
77+
git clone --depth=1 --branch=1.1 git://github.com/sebastianbergmann/phpunit-mock-objects.git
78+
git clone --depth=1 --branch=1.1 git://github.com/sebastianbergmann/phpunit-selenium.git
79+
git clone --depth=1 --branch=1.0.0 git://github.com/sebastianbergmann/phpunit-story.git
80+
81+
# and the version of phpunit that we expect to run with php 5.2
82+
git clone --depth=1 --branch=3.6 git://github.com/sebastianbergmann/phpunit.git
83+
84+
# fix up the version number of phpunit
85+
sed -i 's/@package_version@/3.6-git/g' phpunit/PHPUnit/Runner/Version.php
86+
87+
# now set up an ini file that adds all of the above to include_path for the PHP5.2 install
88+
mkdir -p ${PHP52_PATH}/var/db
89+
echo "include_path=.:${PHP52_PATH}/lib/php:${PHP52_PATH}/lib/php/dbunit:${PHP52_PATH}/lib/php/php-code-coverage:${PHP52_PATH}/lib/php/php-file-iterator:${PHP52_PATH}/lib/php/php-invoker:${PHP52_PATH}/lib/php/php-text-template:${PHP52_PATH}/lib/php/php-timer:${PHP52_PATH}/lib/php/php-token-stream:${PHP52_PATH}/lib/php/phpunit-mock-objects:${PHP52_PATH}/lib/php/phpunit-selenium:${PHP52_PATH}/lib/php/phpunit-story:${PHP52_PATH}/lib/php/phpunit" > ${PHP52_PATH}/var/db/path.ini
90+
91+
# one more PHPUnit dependency that we need to install using pear under PHP5.2
92+
cd $HOME
93+
export PHPBREW_RC_ENABLE=1
94+
source $HOME/.phpbrew/bashrc
95+
phpbrew use 5.2.17
96+
pear channel-discover pear.symfony-project.com
97+
pear install pear.symfony-project.com/YAML-1.0.2
98+
99+
# manually go back to the system php, we can't use `phpbrew switch-off`
100+
# because we're running a version of php that phpbrew doesn't work with at this point
101+
unset PHPBREW_PHP
102+
unset PHPBREW_PATH
103+
__phpbrew_set_path
104+
__phpbrew_reinit
105+
eval `$BIN env`
106+
107+
# clean up build directory
108+
rm -rf $HOME/.phpbrew/build/*
109+
fi
110+
111+
# all needed php versions and phpunit versions are installed, either from the above
112+
# install script, or from travis cache, so switch to using them
113+
cd $HOME
114+
export PHPBREW_RC_ENABLE=1
115+
source $HOME/.phpbrew/bashrc
116+
117+
if [[ ${SWITCH_TO_PHP:0:3} == "5.2" ]]; then
118+
phpbrew use 5.2.17
119+
else
120+
phpbrew use 5.3.29
121+
fi
122+
fi
123+
124+
cd $ORIG_DIR

bin/patches/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This directory contains patches required to build
2+
older versions of PHP on trusty.

bin/patches/node.patch

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
--- ext/dom/node.c 2012-08-06 17:49:48.826716692 +0800
2+
+++ ext/dom/node.c 2012-08-06 17:52:47.633484660 +0800
3+
@@ -1895,9 +1895,17 @@ static void dom_canonicalization(INTERNA
4+
RETVAL_FALSE;
5+
} else {
6+
if (mode == 0) {
7+
+#ifdef LIBXML2_NEW_BUFFER
8+
+ ret = xmlOutputBufferGetSize(buf);
9+
+#else
10+
ret = buf->buffer->use;
11+
+#endif
12+
if (ret > 0) {
13+
+#ifdef LIBXML2_NEW_BUFFER
14+
+ RETVAL_STRINGL((char *) xmlOutputBufferGetContent(buf), ret, 1);
15+
+#else
16+
RETVAL_STRINGL((char *) buf->buffer->content, ret, 1);
17+
+#endif
18+
} else {
19+
RETVAL_EMPTY_STRING();
20+
}
21+
--- ext/dom/documenttype.c 2012-08-06 18:02:16.019640870 +0800
22+
+++ ext/dom/documenttype.c 2012-08-06 18:06:16.612228905 +0800
23+
@@ -205,7 +205,13 @@ int dom_documenttype_internal_subset_rea
24+
if (buff != NULL) {
25+
xmlNodeDumpOutput (buff, NULL, (xmlNodePtr) intsubset, 0, 0, NULL);
26+
xmlOutputBufferFlush(buff);
27+
+
28+
+#ifdef LIBXML2_NEW_BUFFER
29+
+ ZVAL_STRINGL(*retval, xmlOutputBufferGetContent(buff),
30+
+ xmlOutputBufferGetSize(buff), 1);
31+
+#else
32+
ZVAL_STRINGL(*retval, buff->buffer->content, buff->buffer->use, 1);
33+
+#endif
34+
(void)xmlOutputBufferClose(buff);
35+
return SUCCESS;
36+
}
37+
--- ext/simplexml/simplexml.c 2012-08-06 18:10:44.621017026 +0800
38+
+++ ext/simplexml/simplexml.c 2012-08-06 18:12:48.016270419 +0800
39+
@@ -1417,7 +1417,12 @@ SXE_METHOD(asXML)
40+
41+
xmlNodeDumpOutput(outbuf, (xmlDocPtr) sxe->document->ptr, node, 0, 0, ((xmlDocPtr) sxe->document->ptr)->encoding);
42+
xmlOutputBufferFlush(outbuf);
43+
+#ifdef LIBXML2_NEW_BUFFER
44+
+ RETVAL_STRINGL((char *)xmlOutputBufferGetContent(outbuf),
45+
+ xmlOutputBufferGetSize(outbuf), 1);
46+
+#else
47+
RETVAL_STRINGL((char *)outbuf->buffer->content, outbuf->buffer->use, 1);
48+
+#endif
49+
xmlOutputBufferClose(outbuf);
50+
}
51+
} else {

bin/patches/openssl.patch

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
--- ext/openssl/xp_ssl.c
2+
+++ ext/openssl/xp_ssl.c
3+
@@ -328,10 +328,12 @@ static inline int php_openssl_setup_cryp
4+
sslsock->is_client = 1;
5+
method = SSLv23_client_method();
6+
break;
7+
+#ifndef OPENSSL_NO_SSL2
8+
case STREAM_CRYPTO_METHOD_SSLv2_CLIENT:
9+
sslsock->is_client = 1;
10+
method = SSLv2_client_method();
11+
break;
12+
+#endif
13+
case STREAM_CRYPTO_METHOD_SSLv3_CLIENT:
14+
sslsock->is_client = 1;
15+
method = SSLv3_client_method();
16+
@@ -348,10 +350,12 @@ static inline int php_openssl_setup_cryp
17+
sslsock->is_client = 0;
18+
method = SSLv3_server_method();
19+
break;
20+
+#ifndef OPENSSL_NO_SSL2
21+
case STREAM_CRYPTO_METHOD_SSLv2_SERVER:
22+
sslsock->is_client = 0;
23+
method = SSLv2_server_method();
24+
break;
25+
+#endif
26+
case STREAM_CRYPTO_METHOD_TLS_SERVER:
27+
sslsock->is_client = 0;
28+
method = TLSv1_server_method();
29+
@@ -629,9 +633,11 @@ static inline int php_openssl_tcp_sockop
30+
case STREAM_CRYPTO_METHOD_SSLv23_CLIENT:
31+
sock->method = STREAM_CRYPTO_METHOD_SSLv23_SERVER;
32+
break;
33+
+#ifndef OPENSSL_NO_SSL2
34+
case STREAM_CRYPTO_METHOD_SSLv2_CLIENT:
35+
sock->method = STREAM_CRYPTO_METHOD_SSLv2_SERVER;
36+
break;
37+
+#endif
38+
case STREAM_CRYPTO_METHOD_SSLv3_CLIENT:
39+
sock->method = STREAM_CRYPTO_METHOD_SSLv3_SERVER;
40+
break;
41+
@@ -911,9 +917,11 @@ php_stream *php_openssl_ssl_socket_facto
42+
if (strncmp(proto, "ssl", protolen) == 0) {
43+
sslsock->enable_on_connect = 1;
44+
sslsock->method = STREAM_CRYPTO_METHOD_SSLv23_CLIENT;
45+
+#ifndef OPENSSL_NO_SSL2
46+
} else if (strncmp(proto, "sslv2", protolen) == 0) {
47+
sslsock->enable_on_connect = 1;
48+
sslsock->method = STREAM_CRYPTO_METHOD_SSLv2_CLIENT;
49+
+#endif
50+
} else if (strncmp(proto, "sslv3", protolen) == 0) {
51+
sslsock->enable_on_connect = 1;
52+
sslsock->method = STREAM_CRYPTO_METHOD_SSLv3_CLIENT;

0 commit comments

Comments
 (0)