From 025cb9c66aabe6ab4da0d6e2f8008ab2cba52cac Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Mon, 24 Feb 2025 23:48:57 +0000 Subject: [PATCH] MDL-84639 reportbuilder: replace deprecated trait test mocking. "getObjectForTrait() is deprecated and will be removed in PHPUnit 12 without replacement." See: https://github.com/sebastianbergmann/phpunit/issues/5244 --- .../tests/local/helpers/join_trait_test.php | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/reportbuilder/tests/local/helpers/join_trait_test.php b/reportbuilder/tests/local/helpers/join_trait_test.php index 5e9dbe765ad..5d11289e480 100644 --- a/reportbuilder/tests/local/helpers/join_trait_test.php +++ b/reportbuilder/tests/local/helpers/join_trait_test.php @@ -14,12 +14,22 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * Unit tests for the join trait + * + * @package core_reportbuilder + * @copyright 2024 Paul Holden + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + declare(strict_types=1); namespace core_reportbuilder\local\helpers; use advanced_testcase; +defined('MOODLE_INTERNAL') || die(); + /** * Unit tests for the join trait * @@ -34,9 +44,7 @@ final class join_trait_test extends advanced_testcase { * Test adding single join */ public function test_add_join(): void { - - /** @var join_trait $trait */ - $trait = $this->getObjectForTrait(join_trait::class); + $trait = new join_trait_mock(); $trait->add_join('JOIN {test} t ON t.id = a.id'); $this->assertEquals(['JOIN {test} t ON t.id = a.id'], $trait->get_joins()); @@ -46,9 +54,7 @@ final class join_trait_test extends advanced_testcase { * Test adding single join multiple times */ public function test_add_join_multiple(): void { - - /** @var join_trait $trait */ - $trait = $this->getObjectForTrait(join_trait::class); + $trait = new join_trait_mock(); // Add multiple joins, two of which are duplicates. $trait->add_join('JOIN {test} t1 ON t1.id = a.id') @@ -66,9 +72,7 @@ final class join_trait_test extends advanced_testcase { * Test adding multiple joins */ public function test_add_joins(): void { - - /** @var join_trait $trait */ - $trait = $this->getObjectForTrait(join_trait::class); + $trait = new join_trait_mock(); // Add multiple joins, two of which are duplicates. $trait->add_joins([ @@ -84,3 +88,10 @@ final class join_trait_test extends advanced_testcase { ], $trait->get_joins()); } } + +/** + * Simple implementation of a class using the trait + */ +final class join_trait_mock { + use join_trait; +}