From d04581848d36510ee74e9eae7731b88b435ce459 Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Thu, 4 Jul 2024 11:50:40 +0200 Subject: [PATCH] fix codechecker warnings --- tests/backup_restore_test.php | 4 ++-- tests/cron_test.php | 2 +- tests/locallib_test.php | 23 +++++++++++++++---- tests/mod_generator_test.php | 2 +- .../mod_ratingallocate_choice_groups_test.php | 2 +- ...od_ratingallocate_choice_importer_test.php | 2 +- ...d_ratingallocate_privacy_provider_test.php | 2 +- tests/mod_ratingallocate_processor_test.php | 7 +++++- tests/mod_ratingallocate_solver_test.php | 14 ++++++++++- tests/mod_ratingallocate_status_test.php | 4 ++-- tests/mod_ratingallocate_strategy_test.php | 13 +++++++++++ 11 files changed, 60 insertions(+), 15 deletions(-) diff --git a/tests/backup_restore_test.php b/tests/backup_restore_test.php index bfb98946..273942c4 100644 --- a/tests/backup_restore_test.php +++ b/tests/backup_restore_test.php @@ -37,9 +37,9 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @covers \backup\moodle2 */ -class backup_restore_test extends \advanced_testcase { +final class backup_restore_test extends \advanced_testcase { - public function test_backup_restore() { + public function test_backup_restore(): void { // TODO this test does not check if userids are correctly mapped. global $CFG, $DB; \core_php_time_limit::raise(); diff --git a/tests/cron_test.php b/tests/cron_test.php index c9323a31..fc2b6454 100644 --- a/tests/cron_test.php +++ b/tests/cron_test.php @@ -36,7 +36,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @covers \classes\task\cron_task */ -class cron_test extends \advanced_testcase { +final class cron_test extends \advanced_testcase { /** @var $teacher */ private $teacher; diff --git a/tests/locallib_test.php b/tests/locallib_test.php index cba06e9a..8fd7881d 100644 --- a/tests/locallib_test.php +++ b/tests/locallib_test.php @@ -33,9 +33,9 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @covers \locallib */ -class locallib_test extends \advanced_testcase { +final class locallib_test extends \advanced_testcase { - public function test_simple() { + public function test_simple(): void { global $DB; \core_php_time_limit::raise(); $this->resetAfterTest(); @@ -145,6 +145,13 @@ public function test_simple() { . 'a student, so this one should not have been distributed.'); } + /** + * Filter allocations by choice + * + * @param $allocations + * @param $choiceid + * @return array + */ private static function filter_allocations_by_choice($allocations, $choiceid) { $filterchoiceid = function($elem) use ($choiceid) { return $elem->{this_db\ratingallocate_allocations::CHOICEID} == $choiceid; @@ -292,8 +299,16 @@ public function test_reset_userdata(): void { $this->assertEquals(2, count($ratingallocate->get_allocations())); // Keep dates for comparison. - $accesstimestart = $DB->get_record('ratingallocate', ['id' => $ratingallocate->get_ratingallocateid()], 'accesstimestart')->accesstimestart; - $accesstimestop = $DB->get_record('ratingallocate', ['id' => $ratingallocate->get_ratingallocateid()], 'accesstimestop')->accesstimestop; + $accesstimestart = $DB->get_record( + 'ratingallocate', + ['id' => $ratingallocate->get_ratingallocateid()], + 'accesstimestart' + )->accesstimestart; + $accesstimestop = $DB->get_record( + 'ratingallocate', + ['id' => $ratingallocate->get_ratingallocateid()], + 'accesstimestop' + )->accesstimestop; // Now try and reset. $data = new \stdClass(); diff --git a/tests/mod_generator_test.php b/tests/mod_generator_test.php index 41fedfa6..f3c2d233 100644 --- a/tests/mod_generator_test.php +++ b/tests/mod_generator_test.php @@ -30,7 +30,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @covers \mod_ratingallocate_generator */ -class mod_generator_test extends \advanced_testcase { +final class mod_generator_test extends \advanced_testcase { public function test_create_instance(): void { diff --git a/tests/mod_ratingallocate_choice_groups_test.php b/tests/mod_ratingallocate_choice_groups_test.php index 8284838b..4c67cee5 100644 --- a/tests/mod_ratingallocate_choice_groups_test.php +++ b/tests/mod_ratingallocate_choice_groups_test.php @@ -29,7 +29,7 @@ * @author David Thompson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_ratingallocate_choice_groups_test extends \advanced_testcase { +final class mod_ratingallocate_choice_groups_test extends \advanced_testcase { /** Helper function - Create a range of choices. * diff --git a/tests/mod_ratingallocate_choice_importer_test.php b/tests/mod_ratingallocate_choice_importer_test.php index 30081e36..d8711e28 100644 --- a/tests/mod_ratingallocate_choice_importer_test.php +++ b/tests/mod_ratingallocate_choice_importer_test.php @@ -30,7 +30,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @covers \choice_importer */ -class mod_ratingallocate_choice_importer_test extends \advanced_testcase { +final class mod_ratingallocate_choice_importer_test extends \advanced_testcase { /** * Return lines of text for a sample CSV file. diff --git a/tests/mod_ratingallocate_privacy_provider_test.php b/tests/mod_ratingallocate_privacy_provider_test.php index 01f02750..0bce183e 100644 --- a/tests/mod_ratingallocate_privacy_provider_test.php +++ b/tests/mod_ratingallocate_privacy_provider_test.php @@ -38,7 +38,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @covers \classes\privacy\provider */ -class mod_ratingallocate_privacy_provider_test extends \core_privacy\tests\provider_testcase { +final class mod_ratingallocate_privacy_provider_test extends \core_privacy\tests\provider_testcase { /** @var \mod_ratingallocate_generated_module $testmodule */ protected $testmodule; diff --git a/tests/mod_ratingallocate_processor_test.php b/tests/mod_ratingallocate_processor_test.php index 6c73bd33..ca574acf 100644 --- a/tests/mod_ratingallocate_processor_test.php +++ b/tests/mod_ratingallocate_processor_test.php @@ -28,7 +28,7 @@ * @copyright reischmann * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_ratingallocate_processor_test extends \advanced_testcase { +final class mod_ratingallocate_processor_test extends \advanced_testcase { public function setUp(): void { global $PAGE; @@ -131,6 +131,11 @@ public function test_ratings_table_filter(): void { } + /** + * @return void + * @throws \coding_exception + * @covers \classes\ratings_and_allocations_table + */ public function test_ratings_table_groupfilter(): void { $this->resetAfterTest(); diff --git a/tests/mod_ratingallocate_solver_test.php b/tests/mod_ratingallocate_solver_test.php index 31ecebe8..0c24dd7c 100644 --- a/tests/mod_ratingallocate_solver_test.php +++ b/tests/mod_ratingallocate_solver_test.php @@ -33,8 +33,15 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @covers \solver */ -class mod_ratingallocate_solver_test extends \basic_testcase { +final class mod_ratingallocate_solver_test extends \basic_testcase { + /** + * Perform race. + * + * @param $groupsnum + * @param $ratersnum + * @return array + */ private function perform_race($groupsnum, $ratersnum) { $groupsmaxsizemin = floor($ratersnum / $groupsnum); $groupsmaxsizemax = ceil($ratersnum / $groupsnum) + 1; @@ -89,6 +96,11 @@ private function perform_race($groupsnum, $ratersnum) { return $result; } + /** + * Test on random. + * + * @return void + */ public function teston_random() { if (!PHPUNIT_LONGTEST) { return; // This test takes longer than 10s. diff --git a/tests/mod_ratingallocate_status_test.php b/tests/mod_ratingallocate_status_test.php index 730499b4..00c7f495 100644 --- a/tests/mod_ratingallocate_status_test.php +++ b/tests/mod_ratingallocate_status_test.php @@ -33,7 +33,7 @@ * @copyright reischmann * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_ratingallocate_status_test extends \advanced_testcase { +final class mod_ratingallocate_status_test extends \advanced_testcase { public function setUp(): void { global $PAGE; @@ -46,7 +46,7 @@ public function setUp(): void { * * @return array */ - public function ratingallocate_provider(): array { + public static function ratingallocate_provider(): array { return [ 'Rating phase is not started.' => [ 3, 6, false, false, \ratingallocate::DISTRIBUTION_STATUS_TOO_EARLY], diff --git a/tests/mod_ratingallocate_strategy_test.php b/tests/mod_ratingallocate_strategy_test.php index 53903527..92363ad4 100644 --- a/tests/mod_ratingallocate_strategy_test.php +++ b/tests/mod_ratingallocate_strategy_test.php @@ -35,6 +35,9 @@ final class mod_ratingallocate_strategy_test extends \advanced_testcase { /** * Test for correct validation of settings + * + * @return void + * @covers \strategy\strategy01_yes_no */ public function test_yes_no_validation(): void { // Attribute required. @@ -53,6 +56,8 @@ public function test_yes_no_validation(): void { /** * Test for correct validation of settings + * + * @covers \strategy\strategy02_yes_maybe_no */ public function test_yes_maybe_no_validation(): void { // Attribute required. @@ -71,6 +76,8 @@ public function test_yes_maybe_no_validation(): void { /** * Test for correct validation of settings + * + * @covers \strategy\strategy03_lickert */ public function test_lickert_validation(): void { // Attribute required. @@ -101,6 +108,8 @@ public function test_lickert_validation(): void { /** * Test for correct validation of settings + * + * @covers \strategy\strategy04_points */ public function test_points_validation(): void { // Attribute required. @@ -143,6 +152,8 @@ public function test_points_validation(): void { /** * Test for correct validation of settings + * + * @covers \strategy\strategy05_order */ public function test_order_validation(): void { // Attribute required. @@ -161,6 +172,8 @@ public function test_order_validation(): void { /** * Test for correct validation of settings + * + * @covers \strategy\strategy06_tickyes */ public function test_tickyes_validation(): void { // Attribute required.