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?
How to Run Tests in PHPUnit. You can run all the tests in a directory using the PHPUnit binary installed in your vendor folder. You can also run a single test by providing the path to the test file. You use the --verbose flag to get more information on the test status.
PHPUnit is a unit testing framework for the PHP programming language. It is an instance of the xUnit design for unit testing systems that began with SUnit and became popular with JUnit. Even a small software development project usually takes hours of hard work.
Codeception is a framework used for creating tests, including unit tests, functional tests, and acceptance tests. Despite the fact that it is based on PHP, the user needs only basic knowledge for starting work with the framework, thanks to the set of custom commands offered by Codeception.
You can get the version of PHPUnit running using the \PHPUnit\Runner\Version
[git] class and its static id()
method:
$phpUnitVersion = \PHPUnit\Runner\Version::id(); # 9.5.19
And based on that - halt your tests execution or do whatever you want.
Before PHPUnit fully switched to PHP namespaces (PHPUnit 6), the old class-name was PHPUnit_Runner_Version
[git].
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