MDL-81266 phpunit: Remove expect(Deprecation|Notice|Warning|Error)

PHPUnit 9.6 has deprecated all the expect(Deprecation|Notice|Warning|Error)
assertions, so we have to move away from them.

In core, we only had 2 cases, one easily fixed by getting rid of it,
because, for php >= 80 it's an assert-able exception.

And the other replaced with code that, temporarily, sets a custom
error handler that converts any specified E_ to an asset-able
exception.

Note that tests playing with error handlers should, always, be
run in separate process, to avoid problems or conflicts with
PHPUnit / Moodle own error handlers.
This commit is contained in:
Eloy Lafuente (stronk7)
2024-03-25 16:21:53 +01:00
parent 08027e408c
commit 4c2f8b3a91
2 changed files with 10 additions and 6 deletions
+9 -1
View File
@@ -369,7 +369,15 @@ class advanced_test extends \advanced_testcase {
]);
if ($phpwarn) {
$this->expectWarning();
// Let's convert the warnings into an assert-able exception.
set_error_handler(
static function ($errno, $errstr) {
restore_error_handler();
throw new \Exception($errstr, $errno);
},
E_WARNING // Or any other specific E_ that we want to assert.
);
$this->expectException(\Exception::class);
}
$this->assertEventContextNotUsed($event);
}