MDL-78160 lib: Added class properties that are not declared in dml

In PHP 8.2 and later, setting a value to an undeclared class property is
deprecated and emits a deprecation notice.
So we need to add missing class properties that still need to be declared.

At the test_transaction_with_events() I changed $this->_called into $called local var,
since the $called is used inside the anonymous function I added the third param as
a variable passed by reference so the last assert can get the newest value.
This commit is contained in:
Meirza
2023-06-19 19:57:43 +07:00
committed by meirzamoodle
parent 95e0d9ce66
commit 22d912df33
3 changed files with 11 additions and 13 deletions
+4 -4
View File
@@ -400,15 +400,15 @@ class dml_read_slave_test extends \base_testcase {
$this->assertNull($DB->get_dbhwrite());
$this->_called = false;
$called = false;
$transaction = $DB->start_delegated_transaction();
$now = microtime(true);
$observers = [
[
'eventname' => '\core_tests\event\unittest_executed',
'callback' => function (\core_tests\event\unittest_executed $event) use ($DB, $now) {
$this->_called = true;
'callback' => function (\core_tests\event\unittest_executed $event) use ($DB, $now, &$called) {
$called = true;
$this->assertFalse($DB->is_transaction_started());
// This condition should always evaluate true, however we need to
@@ -448,7 +448,7 @@ class dml_read_slave_test extends \base_testcase {
$event->trigger();
$transaction->allow_commit();
$this->assertTrue($this->_called);
$this->assertTrue($called);
});
}
-8
View File
@@ -80,14 +80,6 @@ class read_slave_moodle_database extends test_moodle_database {
protected function commit_transaction() {
}
/**
* Abort database transaction
* @return void
*/
protected function rollback_transaction() {
$this->txnhandle = $this->handle;
}
/**
* Query wrapper that calls query_start() and query_end()
* @param string $sql
+7 -1
View File
@@ -25,6 +25,8 @@
namespace core;
use ReflectionProperty;
/**
* Read slave helper that exposes selected moodle_read_slave_trait metods
*
@@ -49,7 +51,11 @@ trait test_moodle_read_slave_trait {
fputs($ro, 'ro');
$this->prefix = 'test_'; // Default, not to leave empty.
$this->wantreadslave = true;
$rcp = new ReflectionProperty(parent::class, 'wantreadslave');
$rcp->setAccessible(true);
$rcp->setValue($this, true);
$this->dbhwrite = $rw;
$this->dbhreadonly = $ro;
$this->set_db_handle($this->dbhwrite);