|
| 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 |
0 commit comments