Reputation: 5086
Is there any way of configuring a php project so that its phpunit test cases can be executed on (PHP 5.3), PHP 5.4, PHP 5.5, PHP 5.6 and PHP 7?
I came across this issue, when I've set the phpunit require-dev dependency in my project to 5.4, while I configured travis to test the project for PHP 5.4, PHP 5.5, PHP 5.6 and PHP 7 and then realized it is failing because phpunit 5.4 only works from PHP 5.6 and PHP 7. But phpunit 4.8 doesn't work for PHP 7. Setting the dependency to *
doesn't help, since phpunit 5.4 uses namespaces and phpunit 4.8 the underscore names.
Is there any way of configuring a project, so that I can run the phpunit tests on all the version (PHP 5.3), PHP 5.4, PHP 5.5, PHP 5.6 and PHP 7 from the same code-base? (Namespaces where introduced in 5.3.0.)
Upvotes: 1
Views: 911
Reputation: 392
For all PHP 5.x, you can just configure your test cases to extend \PHPUnit_Framework_TestCase
, PHPUnit 5.7 is compatible with both the underscore names and the namespaced names, but this won't work for PHP 7, as later versions of PHPUnit have dropped the global underscore name.
It is safe to switch to \PHPUnit\Framework\TestCase
once you no longer wish to test against PHP 5.5 and earlier.
Upvotes: 1