Skip to content

Commit c97aefc

Browse files
committed
Improve coverage information
Add missing cover annotations and add new coverage annotation style for phpunit 12
1 parent 634160f commit c97aefc

File tree

6 files changed

+64
-4
lines changed

6 files changed

+64
-4
lines changed

tests/backup_restore_test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* @group mod_ratingallocate
3737
* @copyright usener
3838
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39-
* @covers \mod_ratingallocate\backup_ratingallocate_activity_structure_step
39+
* @covers \mod_ratingallocate\backup_ratingallocate_activity_structure_step (This is deprecated from phpunit 12 onwards)
4040
*/
4141
#[CoversClass(backup_ratingallocate_activity_structure_step::class)]
4242
final class backup_restore_test extends \advanced_testcase {

tests/cron_test.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use mod_ratingallocate\db as this_db;
2525
use mod_ratingallocate\task\cron_task;
2626
use PHPUnit\Framework\Attributes\CoversClass;
27+
use PHPUnit\Framework\Attributes\CoversFunction;
2728

2829
/**
2930
* mod_ratingallocate cron tests
@@ -39,6 +40,7 @@
3940
* @covers \mod_ratingallocate\task\cron_task
4041
*/
4142
#[CoversClass(cron_task::class)]
43+
#[CoversFunction('execute')]
4244
final class cron_test extends \advanced_testcase {
4345

4446
/** @var $teacher */

tests/locallib_test.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,36 @@
2222
require_once(dirname(__FILE__) . '/../locallib.php');
2323

2424
use mod_ratingallocate\db as this_db;
25+
use mod_ratingallocate_generator;
26+
use PHPUnit\Framework\Attributes\CoversClass;
27+
use PHPUnit\Framework\Attributes\CoversFunction;
2528

2629
/**
2730
* mod_ratingallocate generator tests
2831
*
2932
* @package mod_ratingallocate
3033
* @category test
31-
* @group mod_ratingallocate
34+
* @group mod_ratingallocate
3235
* @copyright usener
3336
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34-
* @covers \locallib
37+
* @covers \mod_ratingallocate\ratingallocate
3538
*/
39+
#[CoversClass(ratingallocate::class)]
40+
#[CoversFunction('get_choices_with_allocationcount')]
41+
#[CoversFunction('distribute_choices')]
42+
#[CoversFunction('get_options_titles')]
43+
#[CoversFunction('get_allocations')]
44+
#[CoversFunction('get_ratings_for_rateable_choices')]
3645
final class locallib_test extends \advanced_testcase {
3746

47+
/**
48+
* Tests a simple allocation scenario.
49+
*
50+
* @return void
51+
* @throws \coding_exception
52+
* @throws \dml_exception
53+
* @covers \mod_ratingallocate\ratingallocate::distribute_choices
54+
*/
3855
public function test_simple(): void {
3956
global $DB;
4057
\core_php_time_limit::raise();
@@ -221,7 +238,9 @@ public function test_get_option_titles_custom1(): void {
221238
}
222239

223240
/**
224-
* Test if option titles are returned according to a mixture of defined and custom values,
241+
* Test if option titles are returned according to a mixture of defined and custom values
242+
*
243+
* @covers \mod_ratingallocate\ratingallocate::get_options_titles
225244
*/
226245
public function test_get_option_titles_mixed(): void {
227246
$settings = [1 => 'Ja1234']; // Test data.
@@ -239,6 +258,11 @@ public function test_get_option_titles_mixed(): void {
239258
$this->assertEquals($expectedresult, $result);
240259
}
241260

261+
/**
262+
* Test if reset_userdata works as expected.
263+
*
264+
* @covers \mod_ratingallocate\ratingallocate::distribute_choices
265+
*/
242266
public function test_reset_userdata(): void {
243267
global $DB;
244268

tests/mod_generator_test.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
1616

1717
namespace mod_ratingallocate;
18+
use mod_ratingallocate_generator;
19+
use PHPUnit\Framework\Attributes\CoversClass;
20+
1821
defined('MOODLE_INTERNAL') || die();
1922

2023
global $CFG;
@@ -30,8 +33,14 @@
3033
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3134
* @covers \mod_ratingallocate_generator
3235
*/
36+
#[CoversClass(mod_ratingallocate_generator::class)]
3337
final class mod_generator_test extends \advanced_testcase {
3438

39+
/**
40+
* Test the creation of a mod_ratingallocate instance with choices.
41+
*
42+
* @covers \mod_ratingallocate_generator::create_instance_with_choices
43+
*/
3544
public function test_create_instance(): void {
3645

3746
global $DB, $USER;

tests/mod_ratingallocate_allocate_unrated_test.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
use coding_exception;
2020
use mod_ratingallocate_generator;
21+
use PHPUnit\Framework\Attributes\CoversClass;
22+
use PHPUnit\Framework\Attributes\CoversFunction;
23+
use PHPUnit\Framework\Attributes\CoversMethod;
2124
use stdClass;
2225

2326
defined('MOODLE_INTERNAL') || die();
@@ -36,6 +39,14 @@
3639
* @author Philipp Memmel
3740
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3841
*/
42+
#[CoversClass(ratingallocate::class)]
43+
#[CoversFunction('get_choice_groups')]
44+
#[CoversFunction('get_all_groups_of_choices')]
45+
#[CoversFunction('get_user_groupids')]
46+
#[CoversFunction('get_undistributed_users_with_groupscount')]
47+
#[CoversFunction('get_undistributed_users')]
48+
#[CoversFunction('get_choices_with_allocationcount')]
49+
#[CoversFunction('get_allocations_for_user')]
3950
final class mod_ratingallocate_allocate_unrated_test extends \advanced_testcase {
4051

4152
/** @var stdClass Course object. */
@@ -91,6 +102,7 @@ protected function setUp(): void {
91102
* Asserts that there is no allocation violating the group restrictions. This should be called after the algorithms have been
92103
* run to assert that the algorithm did respect the group restrictions when allocating.
93104
*
105+
* @covers ::get_choice_groups
94106
* @return void
95107
*/
96108
private function test_group_memberships(): void {
@@ -322,6 +334,7 @@ public function test_get_undistributed_users(): void {
322334
* Helper method to retrieve the choice id by the title.
323335
*
324336
* @param string $title title of the choice to get the id
337+
* @covers ::get_rateable_choices
325338
* @return int the id of the choice object
326339
*/
327340
private function get_choice_id_by_title(string $title): int {
@@ -395,6 +408,7 @@ private function assert_allocation_of_random_users(): void {
395408
* Test distribution without groups.
396409
*
397410
* @return void
411+
* @covers ::queue_distribution_of_users_without_choice
398412
* @throws coding_exception
399413
*/
400414
public function test_distribution_without_groups(): void {
@@ -464,6 +478,7 @@ public function test_allocation_with_groups_common_features(): void {
464478
* test_allocation_with_groups function.
465479
*
466480
* @param string $algorithm the algorithm to use for running this test function
481+
* @covers ::queue_distribution_of_users_without_choice
467482
* @return void
468483
*/
469484
private function test_allocation_with_groups_with_algorithm(string $algorithm): void {
@@ -524,6 +539,7 @@ private function test_allocation_with_groups_with_algorithm(string $algorithm):
524539
/**
525540
* Test the distribution of users to choices with group restrictions, using both algorithms.
526541
*
542+
* @covers ::queue_distribution_of_users_without_choice
527543
* @return void
528544
* @throws coding_exception
529545
*/
@@ -538,6 +554,7 @@ public function test_allocation_without_groups_common_features(): void {
538554
* This is a private method because she is being called twice to test both algorithms.
539555
*
540556
* @param string $algorithm the algorithm to use for the distribution
557+
* @covers ::queue_distribution_of_users_without_choice
541558
* @return void
542559
* @throws coding_exception
543560
*/
@@ -586,6 +603,7 @@ private function test_allocation_without_groups_with_algorithm(string $algorithm
586603
* Test the EQUALLY algorithm without groups. The algorithm tries to distribute the users so that each choice has equal places
587604
* left or at most there is a difference of one user for the left places per choice.
588605
*
606+
* @covers ::queue_distribution_of_users_without_choice
589607
* @return void
590608
* @throws dml_exception
591609
*/
@@ -638,6 +656,7 @@ public function test_distribute_equally_without_groups(): void {
638656
* Test the FILL algorithm without groups. This algorithm just fills up every choice. Choices with least places left are
639657
* being filled up first.
640658
*
659+
* @covers ::queue_distribution_of_users_without_choice
641660
* @return void
642661
*/
643662
public function test_distribute_fill_without_groups(): void {

tests/mod_ratingallocate_choice_groups_test.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
1616

1717
namespace mod_ratingallocate;
18+
use PHPUnit\Framework\Attributes\CoversClass;
19+
use PHPUnit\Framework\Attributes\CoversFunction;
1820
use stdClass;
1921

2022
defined('MOODLE_INTERNAL') || die();
@@ -31,6 +33,10 @@
3133
* @author David Thompson <[email protected]>
3234
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3335
*/
36+
#[CoversClass(ratingallocate::class)]
37+
#[CoversFunction('get_group_selections')]
38+
#[CoversFunction('filter_choices_by_groups')]
39+
#[CoversFunction('update_choice_groups')]
3440
final class mod_ratingallocate_choice_groups_test extends \advanced_testcase {
3541

3642
/** @var object The environment that will be used for testing

0 commit comments

Comments
 (0)