From 842f76b29591f5b54fd16d18a306d424cdcf0572 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Thu, 2 Nov 2023 16:15:21 +0000 Subject: [PATCH] Fix coding style --- tests/helper.php | 25 ++++++++++--------------- tests/question_single_test.php | 32 ++++++++++++++++++-------------- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/tests/helper.php b/tests/helper.php index 10937eb..f5fdcc7 100644 --- a/tests/helper.php +++ b/tests/helper.php @@ -15,7 +15,7 @@ // along with Moodle. If not, see . /** - * Unit tests for ou matrix question type. + * Unit tests helper for the OU matrix question type. * * @package qtype_oumatrix * @copyright 2023 The Open University @@ -23,11 +23,6 @@ */ class qtype_oumatrix_test_helper extends question_test_helper { - /** - * Returns the test questions. - * - * @return string[] - */ public function get_test_questions(): array { return [ 'animals_single', @@ -38,9 +33,9 @@ public function get_test_questions(): array { /** * Get the question data, as it would be loaded by get_question_options. * - * @return object + * @return stdClass */ - public function get_oumatrix_question_data_animals_single(): object { + public function get_oumatrix_question_data_animals_single(): stdClass { global $USER; $qdata = new stdClass(); @@ -151,9 +146,9 @@ public function get_oumatrix_question_data_animals_single(): object { /** * Get the question data, as it would be loaded by get_question_options. * - * @return object + * @return stdClass */ - public static function get_oumatrix_question_form_data_animals_single(): object { + public static function get_oumatrix_question_form_data_animals_single(): stdClass { $qfdata = new stdClass(); $qfdata->name = 'oumatrix_animals_single01'; @@ -232,9 +227,9 @@ public static function get_oumatrix_question_form_data_animals_single(): object /** * Get the question data, as it would be loaded by get_question_options. * - * @return object + * @return stdClass */ - public function get_oumatrix_question_data_food_multiple(): object { + public function get_oumatrix_question_data_food_multiple(): stdClass { global $USER; $qdata = new stdClass(); @@ -352,9 +347,9 @@ public function get_oumatrix_question_data_food_multiple(): object { /** * Get the question data, as it would be loaded by get_question_options. * - * @return object + * @return stdClass */ - public static function get_oumatrix_question_form_data_food_multiple(): object { + public static function get_oumatrix_question_form_data_food_multiple(): stdClass { $qfdata = new stdClass(); $qfdata->name = 'oumatrix_food_multiple01'; @@ -544,4 +539,4 @@ public function make_oumatrix_question_animals_single(): qtype_oumatrix_single { ]; return $question; } -} \ No newline at end of file +} diff --git a/tests/question_single_test.php b/tests/question_single_test.php index d7d3706..fc292a1 100644 --- a/tests/question_single_test.php +++ b/tests/question_single_test.php @@ -36,16 +36,20 @@ */ class question_single_test extends \advanced_testcase { - public function test_get_expected_data() { + public function test_get_expected_data(): void { $question = \test_question_maker::make_question('oumatrix'); $question->start_attempt(new question_attempt_step(), 1); - $expected = ['rowanswers0' => PARAM_INT, 'rowanswers1' => PARAM_INT, - 'rowanswers2' => PARAM_INT, 'rowanswers3' => PARAM_INT]; - $this->assertEquals($expected , $question->get_expected_data()); + $expected = [ + 'rowanswers0' => PARAM_INT, + 'rowanswers1' => PARAM_INT, + 'rowanswers2' => PARAM_INT, + 'rowanswers3' => PARAM_INT, + ]; + $this->assertEquals($expected, $question->get_expected_data()); } - public function test_is_gradable_response() { + public function test_is_gradable_response(): void { $question = \test_question_maker::make_question('oumatrix'); $question->start_attempt(new question_attempt_step(), 1); @@ -56,7 +60,7 @@ public function test_is_gradable_response() { $this->assertEquals($question->is_gradable_response($response), $question->is_complete_response($response)); } - public function test_is_same_response() { + public function test_is_same_response(): void { $question = \test_question_maker::make_question('oumatrix'); $question->start_attempt(new question_attempt_step(), 1); @@ -83,14 +87,14 @@ public function test_is_same_response() { ['rowanswers0' => '1', 'rowanswers1' => '2', 'rowanswers2' => '3', 'rowanswers3' => '4'])); } - public function test_get_correct_response() { + public function test_get_correct_response(): void { $question = \test_question_maker::make_question('oumatrix', 'animals_single'); $question->start_attempt(new question_attempt_step(), 1); $correct = ['rowanswers0' => '1', 'rowanswers1' => '2', 'rowanswers2' => '3', 'rowanswers3' => '4']; $this->assertEquals($correct, $question->get_correct_response()); } - public function test_summarise_response() { + public function test_summarise_response(): void { $question = \test_question_maker::make_question('oumatrix', 'animals_single'); $question->start_attempt(new question_attempt_step(), 1); @@ -115,15 +119,15 @@ public function test_summarise_response() { $this->assertMatchesRegularExpression($expected, $actual); } - public function test_is_complete_response() { + public function test_is_complete_response(): void { $question = \test_question_maker::make_question('oumatrix'); $question->start_attempt(new question_attempt_step(), 1); - // Not complete responses + // Not complete responses. $this->assertFalse($question->is_complete_response([])); $this->assertFalse($question->is_complete_response(['rowanswers0' => '1'])); $this->assertFalse($question->is_complete_response(['rowanswers0' => '1', 'rowanswers1' => '2'])); - $this->assertFalse($question->is_complete_response(['rowanswers0' => '1', 'rowanswers1' => '2', 'rowanswers1' => '3'])); + $this->assertFalse($question->is_complete_response(['rowanswers0' => '1', 'rowanswers1' => '2', 'rowanswers2' => '3'])); // Complete responses. $this->assertTrue($question->is_complete_response( @@ -134,7 +138,7 @@ public function test_is_complete_response() { ['rowanswers0' => '4', 'rowanswers1' => '3', 'rowanswers2' => '2', 'rowanswers3' => '1'])); // Incorrect. } - public function test_grade_response() { + public function test_grade_response(): void { $question = \test_question_maker::make_question('oumatrix', 'animals_single'); $question->start_attempt(new question_attempt_step(), 1); @@ -148,10 +152,10 @@ public function test_grade_response() { $this->assertEquals([0.75, question_state::$gradedpartial], $question->grade_response($partialresponse)); $wrongresponse = ['rowanswers0' => '4', 'rowanswers1' => '3', 'rowanswers2' => '2', 'rowanswers3' => '1']; - $this->assertEquals(array(0, question_state::$gradedwrong), $question->grade_response($wrongresponse)); + $this->assertEquals([0, question_state::$gradedwrong], $question->grade_response($wrongresponse)); } - public function test_get_num_parts_right() { + public function test_get_num_parts_right(): void { $question = \test_question_maker::make_question('oumatrix'); $question->start_attempt(new question_attempt_step(), 1);