I am writing a lib which should work with PHP 5.3+. I want to use generators and closure binding, but those features are 5.5+ and 5.4+. Most of the lib can work without those features, so I want to run certain unit tests only when the php has the proper version. Is there a simple way to do this?
I am looking for something like this:
/** @version 5.4+*/
public function testUsingClosureBind(){...}
/** @version 5.5+*/
public function testUsingGenerators(){...}
but I am open for any suggestion...
There is @requires
annotation support since PHPUnit 3.7 (at least):
<?php
use PHPUnit\Framework\TestCase;
final class SomeTest extends TestCase
{
/**
* @requires PHP 5.3
*/
public function testSome()
{
}
}
See the documentation for more.
Use the version_compare function (http://us3.php.net/manual/en/function.version-compare.php). as an example :
public function testSomething() {
if (version_compare(PHP_VERSION, '5.0', '>=')) {
//do tests for PHP version 5.0 and higher
} else {
//do different tests for php lower than 5.0
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With