Recently I was updating my PHP Lorem Ipsum library in an attempt to get it testing on HHVM on Travis CI alongside the other versions of PHP I was testing against.

Incidentally, the last time I had worked on the project, I had to work out some kinks with older versions of PHP as they required a specific version of Ubuntu and dropped HHVM because I couldn’t get it working properly :(

With HHVM, there is an issue with using PHPUnit greater than 5.7. The newer versions are explicitly for PHP 7.0 and up.

The Travis CI docs are great (and open source!) and provide a solution for the issue, but sadly I couldn’t get things to work quite right.

As I was testing PHP 5.3 up to 7.2 and HHVM in the same project, I needed to dig a bit deeper into the way I was configuring each environment.

To make things work how I wanted them to, I needed to satisfy a few requirements:

  • PHP 5.3 must run on Ubuntu 12.04 LTS
  • PHP 5.4+ can run on Ubuntu 14.04 LTS (including HHVM)
  • PHP environments can rely on local PHPUnit
  • HHVM must use PHPUnit 5.7

This was a bit of a pain because there is no way to pin a specific version of PHPUnit in the compose.json file based on an HHVM environment.

Nothing a little shell scripting couldn’t solve!

To get around this, I omitted PHPUnit from my dependency list. I tend to have it installed globally anyway, so no big deal. Then I hacked in some conditionals to manually install PHPUnit 5.7 when dealing with HHVM environments.

The resulting .travis.yml file look something like this:

language: php
dist: trusty

matrix:
  include:
    - php: 5.3
      dist: precise
    - php: 5.4
    - php: 5.5
    - php: 5.6
    - php: 7.0
    - php: 7.1
    - php: 7.2
    - php: hhvm
      env: HHVM=true

install:
  - composer install
  - if [[ $HHVM == true ]]; then composer require "phpunit/phpunit:5.7"; fi

script:
  - if [[ $HHVM == true ]]; then ./vendor/bin/phpunit .; fi
  - if [[ $HHVM != true ]]; then phpunit .; fi

Gets the job done, but leaves some room for improvement.

Yes, I’m fully away I could have used an else in there ;)