PHPUnit with multiple versions of PHP and HHVM on Travis CI

Josh Sherman
2 min read
Software Development PHP

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:

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 ;)

Join the Conversation

Good stuff? Want more?

Weekly emails about technology, development, and sometimes sauerkraut.

100% Fresh, Grade A Content, Never Spam.

About Josh

Husband. Father. Pug dad. Musician. Founder of Holiday API, Head of Engineering and Emoji Specialist at Mailshake, and author of the best damn Lorem Ipsum Library for PHP.

Currently Reading

Parasie Eve

Previous Reads

Buy Me a Coffee Become a Sponsor

Related Articles