In many cases in our tests we have checks to see whether were using php7 compatible phpunit or php5 compatible phpunit.
if (method_exists($this, 'expectException')) {
$this->expectException(InvalidDataTypeException::class);
$this->expectExceptionMessage('Object support when dumping a YAML file has been disabled.');
}
else {
$this->setExpectedException(InvalidDataTypeException::class, 'Object support when dumping a YAML file has been disabled.');
}
We can now remove these as we should always be able to use expectException.
There is one other example that looks like a phpunit polyfill, and is similar:
if (method_exists($this, 'setExpectedExceptionRegExp')) {
$this->setExpectedExceptionRegExp(InvalidDataTypeException::class, '/^Object support when parsing a YAML file has been disabled/');
}
else {
$this->expectException(InvalidDataTypeException::class);
$this->expectExceptionMessageRegExp('/^Object support when parsing a YAML file has been disabled/');
}
Comments
Comment #2
spokjeDue to #3059090: Deprecate \Drupal\Tests\PhpunitCompatibilityTrait::setExpectedException() there are a lot of these constructions around:
Patch should got rid of those as well.
Let's see what TestBot thinks of this initial patch.
Comment #3
spokjeComment #4
spokjeI think the 2nd test failure in #2 proves that the above isn't a polyfill:
I've left the original, quoted code intact in patch #3, which also should fix the 1st test failure
Comment #5
spokjeComment #6
spokjeComment #7
mondrakesetExpectedExceptionRegExpdoes not exist in PHPUnit 6, so leaving it like in #2 leads to test failure in 8.8.x. It should be removed and useexpectExceptionand<code>expectExceptionMessageRegExpinstead.Comment #8
mondrakeAdded this issue to the Support for PHPUnit 4 has been removed change record.
Comment #9
spokjeThanks @mondrake, especially for the Explanation for Dummies :)
It showed me I'd tackled that the wrong way around.
Comment #10
spokjeRan it through Testbot once more to make sure it passes the latest tests.
Green Testbot = RTBC for me.
Comment #11
alexpottNice tidy up. Thanks.
Committed 3655e08 and pushed to 8.8.x. Thanks!