MDL-81522 phpunit: Add missing void return type to all tests
While this change is not 100% required now, it's good habit and we are checking for it since Moodle 4.4. All the changes in this commit have been applied automatically using the moodle.PHPUnit.TestReturnType sniff and are, exclusively adding the ": void" return types when missing.
This commit is contained in:
@@ -97,7 +97,7 @@ class persistent_test extends advanced_testcase {
|
||||
$dbman->create_table($table);
|
||||
}
|
||||
|
||||
public function test_properties_definition() {
|
||||
public function test_properties_definition(): void {
|
||||
$expected = array(
|
||||
'shortname' => array(
|
||||
'type' => PARAM_TEXT,
|
||||
@@ -203,7 +203,7 @@ class persistent_test extends advanced_testcase {
|
||||
new core_testable_persistent(42);
|
||||
}
|
||||
|
||||
public function test_to_record() {
|
||||
public function test_to_record(): void {
|
||||
$p = new core_testable_persistent();
|
||||
$expected = (object) array(
|
||||
'shortname' => '',
|
||||
@@ -222,7 +222,7 @@ class persistent_test extends advanced_testcase {
|
||||
$this->assertEquals($expected, $p->to_record());
|
||||
}
|
||||
|
||||
public function test_from_record() {
|
||||
public function test_from_record(): void {
|
||||
$p = new core_testable_persistent();
|
||||
$data = (object) array(
|
||||
'shortname' => 'ddd',
|
||||
@@ -242,7 +242,7 @@ class persistent_test extends advanced_testcase {
|
||||
$this->assertEquals($data, $p->to_record());
|
||||
}
|
||||
|
||||
public function test_from_record_invalid_param() {
|
||||
public function test_from_record_invalid_param(): void {
|
||||
$p = new core_testable_persistent();
|
||||
$data = (object) array(
|
||||
'shortname' => 'ddd',
|
||||
@@ -267,7 +267,7 @@ class persistent_test extends advanced_testcase {
|
||||
$this->assertEquals($data, $p->to_record());
|
||||
}
|
||||
|
||||
public function test_validate() {
|
||||
public function test_validate(): void {
|
||||
$data = (object) array(
|
||||
'idnumber' => 'abc',
|
||||
'sortorder' => 0
|
||||
@@ -288,7 +288,7 @@ class persistent_test extends advanced_testcase {
|
||||
$this->assertEquals($expected, $p->get_errors());
|
||||
}
|
||||
|
||||
public function test_validation_required() {
|
||||
public function test_validation_required(): void {
|
||||
$data = (object) array(
|
||||
'idnumber' => 'abc'
|
||||
);
|
||||
@@ -300,7 +300,7 @@ class persistent_test extends advanced_testcase {
|
||||
$this->assertEquals($expected, $p->get_errors());
|
||||
}
|
||||
|
||||
public function test_validation_custom() {
|
||||
public function test_validation_custom(): void {
|
||||
$data = (object) array(
|
||||
'idnumber' => 'abc',
|
||||
'sortorder' => 10,
|
||||
@@ -313,7 +313,7 @@ class persistent_test extends advanced_testcase {
|
||||
$this->assertEquals($expected, $p->get_errors());
|
||||
}
|
||||
|
||||
public function test_validation_custom_message() {
|
||||
public function test_validation_custom_message(): void {
|
||||
$data = (object) array(
|
||||
'idnumber' => 'abc',
|
||||
'sortorder' => 'abc',
|
||||
@@ -326,7 +326,7 @@ class persistent_test extends advanced_testcase {
|
||||
$this->assertEquals($expected, $p->get_errors());
|
||||
}
|
||||
|
||||
public function test_validation_choices() {
|
||||
public function test_validation_choices(): void {
|
||||
$data = (object) array(
|
||||
'idnumber' => 'abc',
|
||||
'sortorder' => 0,
|
||||
@@ -340,7 +340,7 @@ class persistent_test extends advanced_testcase {
|
||||
$this->assertEquals($expected, $p->get_errors());
|
||||
}
|
||||
|
||||
public function test_validation_type() {
|
||||
public function test_validation_type(): void {
|
||||
$data = (object) array(
|
||||
'idnumber' => 'abc',
|
||||
'sortorder' => 'NaN'
|
||||
@@ -350,7 +350,7 @@ class persistent_test extends advanced_testcase {
|
||||
$this->assertArrayHasKey('sortorder', $p->get_errors());
|
||||
}
|
||||
|
||||
public function test_validation_null() {
|
||||
public function test_validation_null(): void {
|
||||
$data = (object) array(
|
||||
'idnumber' => null,
|
||||
'sortorder' => 0,
|
||||
@@ -369,7 +369,7 @@ class persistent_test extends advanced_testcase {
|
||||
$this->assertArrayNotHasKey('scaleid', $p->get_errors());
|
||||
}
|
||||
|
||||
public function test_create() {
|
||||
public function test_create(): void {
|
||||
global $DB;
|
||||
$p = new core_testable_persistent(0, (object) array('sortorder' => 123, 'idnumber' => 'abc'));
|
||||
$this->assertFalse(isset($p->beforecreate));
|
||||
@@ -385,7 +385,7 @@ class persistent_test extends advanced_testcase {
|
||||
$this->assertTrue($p->is_valid()); // Should always be valid after a create.
|
||||
}
|
||||
|
||||
public function test_update() {
|
||||
public function test_update(): void {
|
||||
global $DB;
|
||||
$p = new core_testable_persistent(0, (object) array('sortorder' => 123, 'idnumber' => 'abc'));
|
||||
$p->create();
|
||||
@@ -429,7 +429,7 @@ class persistent_test extends advanced_testcase {
|
||||
$this->assertEquals(1, $record->sortorder);
|
||||
}
|
||||
|
||||
public function test_save() {
|
||||
public function test_save(): void {
|
||||
global $DB;
|
||||
$p = new core_testable_persistent(0, (object) array('sortorder' => 123, 'idnumber' => 'abc'));
|
||||
$this->assertFalse(isset($p->beforecreate));
|
||||
@@ -531,7 +531,7 @@ class persistent_test extends advanced_testcase {
|
||||
$persistent->set_many(['invalid' => 'stuff']);
|
||||
}
|
||||
|
||||
public function test_read() {
|
||||
public function test_read(): void {
|
||||
$p = new core_testable_persistent(0, (object) array('sortorder' => 123, 'idnumber' => 'abc'));
|
||||
$p->create();
|
||||
unset($p->beforevalidate);
|
||||
@@ -547,7 +547,7 @@ class persistent_test extends advanced_testcase {
|
||||
$this->assertEquals($p, $p3);
|
||||
}
|
||||
|
||||
public function test_delete() {
|
||||
public function test_delete(): void {
|
||||
global $DB;
|
||||
|
||||
$p = new core_testable_persistent(0, (object) array('sortorder' => 123, 'idnumber' => 'abc'));
|
||||
@@ -564,12 +564,12 @@ class persistent_test extends advanced_testcase {
|
||||
$this->assertEquals(true, $p->afterdelete);
|
||||
}
|
||||
|
||||
public function test_has_property() {
|
||||
public function test_has_property(): void {
|
||||
$this->assertFalse(core_testable_persistent::has_property('unknown'));
|
||||
$this->assertTrue(core_testable_persistent::has_property('idnumber'));
|
||||
}
|
||||
|
||||
public function test_custom_setter_getter() {
|
||||
public function test_custom_setter_getter(): void {
|
||||
global $DB;
|
||||
|
||||
$path = array(1, 2, 3);
|
||||
@@ -618,7 +618,7 @@ class persistent_test extends advanced_testcase {
|
||||
core_testable_persistent::get_record(['id' => 42], MUST_EXIST);
|
||||
}
|
||||
|
||||
public function test_record_exists() {
|
||||
public function test_record_exists(): void {
|
||||
global $DB;
|
||||
$this->assertFalse($DB->record_exists(core_testable_persistent::TABLE, array('idnumber' => 'abc')));
|
||||
$p = new core_testable_persistent(0, (object) array('sortorder' => 123, 'idnumber' => 'abc'));
|
||||
@@ -630,7 +630,7 @@ class persistent_test extends advanced_testcase {
|
||||
$this->assertFalse(core_testable_persistent::record_exists($id));
|
||||
}
|
||||
|
||||
public function test_get_sql_fields() {
|
||||
public function test_get_sql_fields(): void {
|
||||
$expected = '' .
|
||||
'c.id AS prefix_id, ' .
|
||||
'c.shortname AS prefix_shortname, ' .
|
||||
@@ -647,7 +647,7 @@ class persistent_test extends advanced_testcase {
|
||||
$this->assertEquals($expected, core_testable_persistent::get_sql_fields('c', 'prefix_'));
|
||||
}
|
||||
|
||||
public function test_get_sql_fields_too_long() {
|
||||
public function test_get_sql_fields_too_long(): void {
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessageMatches('/The alias .+ exceeds 30 characters/');
|
||||
core_testable_persistent::get_sql_fields('c');
|
||||
|
||||
Reference in New Issue
Block a user