Someone submitted a pull request to a library of mine wherein a parameter was made optional by replacing something like function doSomething($var)
with fu
You can use the expectException()
method call, instead of the @expectedException
annotation. Using the method call is recommended anyway.
Conditionals in tests are usually a bad idea as tests should be straightforward, but if you insist you could implement the following:
public function testIt()
{
if (PHP_VERSION_ID >= 70100) {
$this->expectException(ArgumentCountError::class);
} else {
$this->expectException(PHPUnit_Framework_Error_Warning::class);
}
// ...
}
You could also implement two separate test cases and skip one or the other based on the PHP version:
public function testItForPHP70()
{
if (PHP_VERSION_ID >= 70100) {
$this->markTestSkipped('PHPUnit_Framework_Error_Warning exception is thrown for legacy PHP versions only');
}
$this->expectException(PHPUnit_Framework_Error_Warning::class);
// ...
}
public function testItForPHP71AndUp()
{
if (PHP_VERSION_ID < 70100) {
$this->markTestSkipped('ArgumentCountError exception is thrown for latest PHP versions only');
}
$this->expectException(ArgumentCountError::class);
// ...
}