MDL-83468 phpunit: Do not throw exception in mocked destructor

PHPUnit removed the ability to mock a destructor, but our lock system
throws an exception if a lock has not been explicitly released in its
destructor.

Normally thhis is fine because the lock is released, and if not then we
want to know about it.

However, where we are mocking the lock, we do not actually obtain the
lock, and we may expect the test to fail.

This change moves the release and notification to a separate, reusable
public method, which is called from the destructor. This allows it to be
mocked at the appropriate time.
This commit is contained in:
Andrew Nicols
2025-01-20 16:47:56 +01:00
committed by Sara Arjona
parent 118b3ccf46
commit 9536ca738e
2 changed files with 27 additions and 11 deletions
+2 -2
View File
@@ -685,8 +685,8 @@ abstract class advanced_testcase extends base_testcase {
$params['userid'] = $matchuserid;
}
$lock = $this->createMock(\core\lock\lock::class);
$cronlock = $this->createMock(\core\lock\lock::class);
$lock = $this->createStub(\core\lock\lock::class);
$cronlock = $this->createStub(\core\lock\lock::class);
$tasks = $DB->get_recordset('task_adhoc', $params);
foreach ($tasks as $record) {