From 81a5016ec77219cb8e50e68a6117d2d254d12c9c Mon Sep 17 00:00:00 2001 From: Meirza Date: Mon, 19 Jun 2023 19:56:07 +0700 Subject: [PATCH] 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. --- lib/dml/tests/dml_read_slave_test.php | 8 ++++---- lib/dml/tests/fixtures/read_slave_moodle_database.php | 8 -------- lib/dml/tests/fixtures/test_moodle_read_slave_trait.php | 8 +++++++- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/dml/tests/dml_read_slave_test.php b/lib/dml/tests/dml_read_slave_test.php index 88e294e26a6..4ded903cb7d 100644 --- a/lib/dml/tests/dml_read_slave_test.php +++ b/lib/dml/tests/dml_read_slave_test.php @@ -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); }); } diff --git a/lib/dml/tests/fixtures/read_slave_moodle_database.php b/lib/dml/tests/fixtures/read_slave_moodle_database.php index c62b81c62bc..a69133fcbf9 100644 --- a/lib/dml/tests/fixtures/read_slave_moodle_database.php +++ b/lib/dml/tests/fixtures/read_slave_moodle_database.php @@ -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 diff --git a/lib/dml/tests/fixtures/test_moodle_read_slave_trait.php b/lib/dml/tests/fixtures/test_moodle_read_slave_trait.php index 1d9d6639156..07d21d8ae88 100644 --- a/lib/dml/tests/fixtures/test_moodle_read_slave_trait.php +++ b/lib/dml/tests/fixtures/test_moodle_read_slave_trait.php @@ -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);