Skip to content

Commit

Permalink
MDL-55091 phpunit: Following has been deprecated.
Browse files Browse the repository at this point in the history
1. getMock()
2. setExpectedException()
3. checkForUnintentionallyCoveredCode renamed to beStrictAboutCoversAnnotation
4. beStrictAboutTestSize renamed to enforceTimeLimit
5. UnitTestCase class is now fully removed.
  • Loading branch information
Rajesh Taneja committed Jul 26, 2016
1 parent 165b70a commit 52f3e06
Show file tree
Hide file tree
Showing 80 changed files with 806 additions and 560 deletions.
17 changes: 12 additions & 5 deletions admin/tool/cohortroles/tests/api_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ protected function setUp() {
cohort_add_member($this->cohort->id, $this->userassignover->id);
}


/**
* @expectedException required_capability_exception
*/
public function test_create_cohort_role_assignment_without_permission() {
$this->setExpectedException('required_capability_exception');
$this->setUser($this->userassignto);
$params = (object) array(
'userid' => $this->userassignto->id,
Expand All @@ -74,8 +75,10 @@ public function test_create_cohort_role_assignment_without_permission() {
api::create_cohort_role_assignment($params);
}

/**
* @expectedException core_competency\invalid_persistent_exception
*/
public function test_create_cohort_role_assignment_with_invalid_data() {
$this->setExpectedException('core_competency\invalid_persistent_exception');
$this->setAdminUser();
$params = (object) array(
'userid' => $this->userassignto->id,
Expand All @@ -99,6 +102,9 @@ public function test_create_cohort_role_assignment() {
$this->assertEquals($result->get_cohortid(), $this->cohort->id);
}

/**
* @expectedException required_capability_exception
*/
public function test_delete_cohort_role_assignment_without_permission() {
$this->setAdminUser();
$params = (object) array(
Expand All @@ -107,11 +113,13 @@ public function test_delete_cohort_role_assignment_without_permission() {
'cohortid' => $this->cohort->id
);
$result = api::create_cohort_role_assignment($params);
$this->setExpectedException('required_capability_exception');
$this->setUser($this->userassignto);
api::delete_cohort_role_assignment($result->get_id());
}

/**
* @expectedException dml_missing_record_exception
*/
public function test_delete_cohort_role_assignment_with_invalid_data() {
$this->setAdminUser();
$params = (object) array(
Expand All @@ -120,7 +128,6 @@ public function test_delete_cohort_role_assignment_with_invalid_data() {
'cohortid' => $this->cohort->id
);
$result = api::create_cohort_role_assignment($params);
$this->setExpectedException('dml_missing_record_exception');
api::delete_cohort_role_assignment($result->get_id() + 1);
}

Expand Down
15 changes: 12 additions & 3 deletions admin/tool/langimport/tests/events_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ public function test_langpack_updated() {
$this->assertEquals(context_system::instance(), $event->get_context());
}

/**
* @expectedException coding_exception
* @expectedExceptionMessage The 'langcode' value must be set to a valid language code
*/
public function test_langpack_updated_validation() {
$this->setExpectedException('coding_exception', 'The \'langcode\' value must be set to a valid language code');

\tool_langimport\event\langpack_updated::event_with_langcode('broken langcode');
}
Expand All @@ -75,8 +78,11 @@ public function test_langpack_installed() {
$this->assertEquals(context_system::instance(), $event->get_context());
}

/**
* @expectedException coding_exception
* @expectedExceptionMessage The 'langcode' value must be set to a valid language code
*/
public function test_langpack_installed_validation() {
$this->setExpectedException('coding_exception', 'The \'langcode\' value must be set to a valid language code');

\tool_langimport\event\langpack_imported::event_with_langcode('broken langcode');
}
Expand All @@ -94,8 +100,11 @@ public function test_langpack_removed() {
$this->assertEquals(context_system::instance(), $event->get_context());
}

/**
* @expectedException coding_exception
* @expectedExceptionMessage The 'langcode' value must be set to a valid language code
*/
public function test_langpack_removed_validation() {
$this->setExpectedException('coding_exception', 'The \'langcode\' value must be set to a valid language code');

\tool_langimport\event\langpack_removed::event_with_langcode('broken langcode');
}
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/monitor/tests/generator_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function test_create_subscription() {
$this->assertEquals(0, $subscription->cmid);

// Make sure rule id is always required.
$this->setExpectedException('coding_exception');
$this->expectException('coding_exception');
unset($record->ruleid);
$monitorgenerator->create_subscription($record);
}
Expand Down
8 changes: 6 additions & 2 deletions admin/tool/monitor/tests/subscription_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ public function setUp() {
$sub->id = 100;
$sub->name = 'My test rule';
$sub->courseid = 20;
$this->subscription = $this->getMock('\tool_monitor\subscription',null, array($sub));
$mockbuilder = $this->getMockBuilder('\tool_monitor\subscription');
$mockbuilder->setMethods(null);
$mockbuilder->setConstructorArgs(array($sub));
$this->subscription = $mockbuilder->getMock();
}

/**
Expand All @@ -56,10 +59,11 @@ public function test_magic_isset() {

/**
* Test for the magic __get method.
*
* @expectedException coding_exception
*/
public function test_magic_get() {
$this->assertEquals(20, $this->subscription->courseid);
$this->setExpectedException('coding_exception');
$this->subscription->ruleid;
}
}
10 changes: 7 additions & 3 deletions admin/tool/uploadcourse/tests/course_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,28 @@
*/
class tool_uploadcourse_course_testcase extends advanced_testcase {

/**
* @expectedException coding_exception
*/
public function test_proceed_without_prepare() {
$this->resetAfterTest(true);
$mode = tool_uploadcourse_processor::MODE_CREATE_NEW;
$updatemode = tool_uploadcourse_processor::UPDATE_NOTHING;
$data = array();
$co = new tool_uploadcourse_course($mode, $updatemode, $data);
$this->setExpectedException('coding_exception');
$co->proceed();
}

/**
* @expectedException moodle_exception
*/
public function test_proceed_when_prepare_failed() {
$this->resetAfterTest(true);
$mode = tool_uploadcourse_processor::MODE_CREATE_NEW;
$updatemode = tool_uploadcourse_processor::UPDATE_NOTHING;
$data = array();
$co = new tool_uploadcourse_course($mode, $updatemode, $data);
$this->assertFalse($co->prepare());
$this->setExpectedException('moodle_exception');
$co->proceed();
}

Expand All @@ -64,7 +68,7 @@ public function test_proceed_when_already_started() {
$co = new tool_uploadcourse_course($mode, $updatemode, $data);
$this->assertTrue($co->prepare());
$co->proceed();
$this->setExpectedException('coding_exception');
$this->expectException('coding_exception');
$co->proceed();
}

Expand Down
8 changes: 6 additions & 2 deletions admin/tool/uploadcourse/tests/processor_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ public function test_shortname_template() {
$this->assertEquals('ID123: Course 1', $c->shortname);
}

/**
* @expectedException moodle_exception
*/
public function test_empty_csv() {
$this->resetAfterTest(true);

Expand All @@ -171,10 +174,12 @@ public function test_empty_csv() {
$cir->init();

$options = array('mode' => tool_uploadcourse_processor::MODE_CREATE_NEW);
$this->setExpectedException('moodle_exception');
$p = new tool_uploadcourse_processor($cir, $options, array());
}

/**
* @expectedException moodle_exception
*/
public function test_not_enough_columns() {
$this->resetAfterTest(true);

Expand All @@ -189,7 +194,6 @@ public function test_not_enough_columns() {
$cir->init();

$options = array('mode' => tool_uploadcourse_processor::MODE_CREATE_NEW);
$this->setExpectedException('moodle_exception');
$p = new tool_uploadcourse_processor($cir, $options, array());
}

Expand Down
18 changes: 13 additions & 5 deletions backup/converter/moodle1/tests/moodle1_converter_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,22 @@ public function test_convert_factory() {
$this->assertInstanceOf('moodle1_converter', $converter);
}

/**
* @expectedException moodle1_convert_storage_exception
*/
public function test_stash_storage_not_created() {
$converter = convert_factory::get_converter('moodle1', $this->tempdir);
$this->setExpectedException('moodle1_convert_storage_exception');
$converter->set_stash('tempinfo', 12);
}

/**
* @expectedException moodle1_convert_empty_storage_exception
*/
public function test_stash_requiring_empty_stash() {
$this->resetAfterTest(true);
$converter = convert_factory::get_converter('moodle1', $this->tempdir);
$converter->create_stash_storage();
$converter->set_stash('tempinfo', 12);
$this->setExpectedException('moodle1_convert_empty_storage_exception');
try {
$converter->get_stash('anothertempinfo');

Expand Down Expand Up @@ -432,6 +436,9 @@ public function test_convert_path_explicit_recipes() {
$this->assertSame(null, $data['nothing']);
}

/**
* @expectedException convert_path_exception
*/
public function test_grouped_data_on_nongrouped_convert_path() {
// prepare some grouped data
$data = array(
Expand All @@ -457,10 +464,12 @@ public function test_grouped_data_on_nongrouped_convert_path() {
$path = new convert_path('beer_style', '/ROOT/BEER_STYLES/BEER_STYLE');

// an attempt to apply recipes throws exception because we do not expect grouped data
$this->setExpectedException('convert_path_exception');
$data = $path->apply_recipes($data);
}

/**
* @expectedException convert_path_exception
*/
public function test_grouped_convert_path_with_recipes() {
// prepare some grouped data
$data = array(
Expand Down Expand Up @@ -488,7 +497,6 @@ public function test_grouped_convert_path_with_recipes() {
$this->assertEquals('Heineken', $data['beers'][1]['beer']['name']);

// an attempt to provide explicit recipes on grouped elements throws exception
$this->setExpectedException('convert_path_exception');
$path = new convert_path(
'beer_style', '/ROOT/BEER_STYLES/BEER_STYLE',
array(
Expand Down Expand Up @@ -573,7 +581,7 @@ public function test_inforef_manager() {
$inforef->add_ref('file', 45);
$inforef->add_refs('file', array(46, 47));
// todo test the write_refs() via some dummy xml_writer
$this->setExpectedException('coding_exception');
$this->expectException('coding_exception');
$inforef->add_ref('unknown_referenced_item_name', 76);
}
}
2 changes: 1 addition & 1 deletion backup/util/xml/parser/tests/parser_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ function helper_check_notifications_order_integrity($notifications) {
* - equal to "value" attribute of the tag (if present)
* - else, equal to tag name
*
* We pass the whole UnitTestCase object to the processor in order to be
* We pass the whole advanced_testcase object to the processor in order to be
* able to perform the tests in the straight in the process
*/
class mock_auto_parser_processor extends progressive_parser_processor {
Expand Down
4 changes: 3 additions & 1 deletion calendar/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ public function test_create_calendar_events () {

/**
* Test delete_calendar_events
*
* @expectedException moodle_exception
*/
public function test_delete_calendar_events() {
global $DB, $USER;
Expand Down Expand Up @@ -247,7 +249,7 @@ public function test_delete_calendar_events() {
$groupevent = $this->create_calendar_event('group', $USER->id, 'group', 0, time(), $record);

$this->setGuestUser();
$this->setExpectedException('moodle_exception');

$events = array(
array('eventid' => $siteevent->id, 'repeat' => 0),
array('eventid' => $courseevent->id, 'repeat' => 0),
Expand Down
4 changes: 3 additions & 1 deletion calendar/tests/ical_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ protected function setUp() {
require_once($CFG->dirroot . '/calendar/lib.php');
}

/**
* @expectedException coding_exception
*/
public function test_calendar_update_subscription() {
$this->resetAfterTest(true);

Expand All @@ -71,7 +74,6 @@ public function test_calendar_update_subscription() {

$subscription = new stdClass();
$subscription->name = 'awesome4';
$this->setExpectedException('coding_exception');
calendar_update_subscription($subscription);
}

Expand Down
6 changes: 4 additions & 2 deletions calendar/tests/rrule_manager_tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,24 @@ public function test_parse_rrule() {

/**
* Test exception is thrown for invalid property.
*
* @expectedException moodle_exception
*/
public function test_parse_rrule_validation() {

$rrule = "RANDOM=PROPERTY;";
$this->setExpectedException('moodle_exception');
$mang = new core_tests_calendar_rrule_manager($rrule);
$mang->parse_rrule();
}

/**
* Test exception is thrown for invalid frequency.
*
* @expectedException moodle_exception
*/
public function test_freq_validation() {

$rrule = "FREQ=RANDOMLY;";
$this->setExpectedException('moodle_exception');
$mang = new core_tests_calendar_rrule_manager($rrule);
$mang->parse_rrule();
}
Expand Down
5 changes: 4 additions & 1 deletion cohort/tests/cohortlib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public function test_cohort_add_cohort() {
$this->assertSame($newcohort->timecreated, $newcohort->timemodified);
}

/**
* @expectedException coding_exception
* @expectedExceptionMessage Missing cohort name in cohort_add_cohort().
*/
public function test_cohort_add_cohort_missing_name() {
$cohort = new stdClass();
$cohort->contextid = context_system::instance()->id;
Expand All @@ -72,7 +76,6 @@ public function test_cohort_add_cohort_missing_name() {
$cohort->description = 'test cohort desc';
$cohort->descriptionformat = FORMAT_HTML;

$this->setExpectedException('coding_exception', 'Missing cohort name in cohort_add_cohort().');
cohort_add_cohort($cohort);
}

Expand Down
Loading

0 comments on commit 52f3e06

Please sign in to comment.