Testing Your Current Code Against
PHP7 Or HHVM

Intro To Dunit. Think Travis-Ci But Locally.

Cory Kennedy-Darby
2 min readMar 31, 2015

DUnit (dee-unit) makes your life easier by allowing you to run your unit tests on different versions of PHP or HHVM. Different versions are possible by using Docker containers. Thanks to @danbruce each of the Docker containers are only, ~35 MB in size.

But PHP7 Is Ages Away Though!

PHP7 isn’t that far away. In fact, it is scheduled for release in ~8 months in November. Now is the perfect time to start testing your code against PHP7 nightly. Why?

1)Backwards Compatibility

Testing against PHP7 allows you the opportunity to report backwards compatibility issues if your current passing unit tests start failing simply by using PHP7.

2)Knowing What Is Changing

One of your passing unit tests begins to fail in PHP7, and you realize that it is a documented backwards compatibility break. Awesome, knowing now is better than when you upgrade. It’ll also push you to keep up to date with the changelogs.

3)Start Convincing Before The Release

I’ve worked and consultant for enough companies to know that convincing the people around you to upgrade from PHP 5.* to 7 will take time. Start testing against PHP7 now, discussing it, and pushing developers around you to do the same. Trust me, getting people on board early will make it a lot smoother down the road.

Installing DUnit

# Use composer to install as require-dev
$ composer require vectorface/dunit --dev

Full installation instructions are located here.

Using DUnit

#Dunit using PHP7 nightly
$ ./vendor/bin/dunit -i "vectorface/php-nightly"
#Dunit using HHVM
$ ./vendor/bin/dunit -i "vectorface/hhvm"

Documentation for using DUnit and all the options it has are located here.

Bonus! DUnit Can Make You Look Brilliant

Imagine this scenario, you’re a developer that works at a company that is currently having a large spike in user growth. You get called into a meeting where you’re told the company is thinking about spending a lot of capital on upgrading the servers because of the growth.

What if you pitched the idea of using HHVM instead? See, the advantage of using DUnit throughout your development is that it provides an insight to how much change would be required to upgrade PHP versions or to move to HHVM.

Wrap Up

DUnit makes it very simple and fast to know if your existing code base doesn’t work with PHP7 & HHVM. Now you have no excuses.

If you enjoyed this article, please recommend or share it.

--

--