soletan soletan - 2 years ago 130
PHP Question

How to detect version of PHPUnit

I'm writing unit tests using an older version of PHPUnit (3.4) and thus can't use all supported assertions listed in manual of 3.5 and 3.6. Though I could reengineer tests for instant support in my environment here, I'd like to make my tests dependent on current version of PHPUnit, so that it's using assertsInstanceOf() as soon as my or any other one's testing environment is providing PHPUnit 3.5+.

I thought there would be some sort of constant automatically defined by PHPUnit, but I couldn't find any documentation on it.

Is there any way of achieving this without requiring definition of constant when calling on command line?

Answer Source

You can get version using PHPUnit_Runner_Version class:

And based on that - halt your tests execution or do whatever you want.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download