MDL-71036 phpunit: Mock->setMethods() silently deprecated

The current ->setMethods() has been silently (won't emit any
warning) in PHPUnit 9. And will stop working (current plans)
in PHPUnit 10.

Basically the now deprecated method has been split into:

- onlyMethods(): To point to existing methods in the mocked artifact.
- addMethods(): To point to non existing (yet) methods in the mocked
  artifact.

In practice that means that all our current setMethods() calls can be
converted to onlyMethods() (existing) and done. The addMethods() is
mostly useful on development phases, not final testing.

Finally note that <null> isn't accepted anymore as parameter to
double all the methods. Instead empty array [] must be used.

Link: https://github.com/sebastianbergmann/phpunit/issues/3770
This commit is contained in:
Eloy Lafuente (stronk7) 2021-03-11 19:31:28 +01:00
parent 8a14a7bd22
commit 81407f18ec
42 changed files with 181 additions and 181 deletions

View File

@ -149,7 +149,7 @@ class tool_behat_manager_util_testcase extends advanced_testcase {
public function test_get_config_file_contents_with_single_run() {
$mockbuilder = $this->getMockBuilder('behat_config_util');
$mockbuilder->setMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_default_theme', 'get_theme_config'));
$mockbuilder->onlyMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_default_theme', 'get_theme_config'));
$behatconfigutil = $mockbuilder->getMock();
@ -188,7 +188,7 @@ class tool_behat_manager_util_testcase extends advanced_testcase {
public function test_get_config_file_contents_with_single_run_no_theme() {
$mockbuilder = $this->getMockBuilder('behat_config_util');
$mockbuilder->setMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_default_theme', 'get_theme_config'));
$mockbuilder->onlyMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_default_theme', 'get_theme_config'));
$behatconfigutil = $mockbuilder->getMock();
@ -242,7 +242,7 @@ class tool_behat_manager_util_testcase extends advanced_testcase {
public function test_get_config_file_contents_with_parallel_run() {
$mockbuilder = $this->getMockBuilder('behat_config_util');
$mockbuilder->setMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_default_theme', 'get_theme_config'));
$mockbuilder->onlyMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_default_theme', 'get_theme_config'));
$behatconfigutil = $mockbuilder->getMock();
@ -345,7 +345,7 @@ class tool_behat_manager_util_testcase extends advanced_testcase {
public function test_get_config_file_contents_with_parallel_run_optimize_tags() {
$mockbuilder = $this->getMockBuilder('behat_config_util');
$mockbuilder->setMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_default_theme', 'get_theme_config'));
$mockbuilder->onlyMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_default_theme', 'get_theme_config'));
$behatconfigutil = $mockbuilder->getMock();
@ -489,7 +489,7 @@ class tool_behat_manager_util_testcase extends advanced_testcase {
public function test_get_config_file_contents_with_blacklisted_tags() {
$mockbuilder = $this->getMockBuilder('behat_config_util');
$mockbuilder->setMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_blacklisted_tests_for_theme',
$mockbuilder->onlyMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_blacklisted_tests_for_theme',
'get_default_theme', 'get_theme_config'));
$behatconfigutil = $mockbuilder->getMock();
@ -553,7 +553,7 @@ class tool_behat_manager_util_testcase extends advanced_testcase {
public function test_get_config_file_contents_with_blacklisted_features_contexts() {
$mockbuilder = $this->getMockBuilder('behat_config_util');
$mockbuilder->setMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_blacklisted_tests_for_theme',
$mockbuilder->onlyMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_blacklisted_tests_for_theme',
'get_default_theme', 'get_theme_config'));
$behatconfigutil = $mockbuilder->getMock();
@ -632,7 +632,7 @@ class tool_behat_manager_util_testcase extends advanced_testcase {
public function test_core_features_to_include_in_specified_theme() {
$mockbuilder = $this->getMockBuilder('behat_config_util');
$mockbuilder->setMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_default_theme', 'get_theme_config'));
$mockbuilder->onlyMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_default_theme', 'get_theme_config'));
$behatconfigutil = $mockbuilder->getMock();

View File

@ -857,7 +857,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$expiredcontext->save();
$mockprivacymanager = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods([
->onlyMethods([
'delete_data_for_user',
'delete_data_for_users_in_context',
'delete_data_for_all_users_in_context',
@ -868,7 +868,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$mockprivacymanager->expects($this->never())->method('delete_data_for_users_in_context');
$manager = $this->getMockBuilder(\tool_dataprivacy\expired_contexts_manager::class)
->setMethods(['get_privacy_manager'])
->onlyMethods(['get_privacy_manager'])
->getMock();
$manager->method('get_privacy_manager')->willReturn($mockprivacymanager);
@ -935,7 +935,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$expiredcontext->save();
$mockprivacymanager = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods([
->onlyMethods([
'delete_data_for_user',
'delete_data_for_users_in_context',
'delete_data_for_all_users_in_context',
@ -956,7 +956,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
}));
$manager = $this->getMockBuilder(\tool_dataprivacy\expired_contexts_manager::class)
->setMethods(['get_privacy_manager'])
->onlyMethods(['get_privacy_manager'])
->getMock();
$manager->method('get_privacy_manager')->willReturn($mockprivacymanager);
@ -1023,7 +1023,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$expiredcontext->save();
$mockprivacymanager = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods([
->onlyMethods([
'delete_data_for_user',
'delete_data_for_users_in_context',
'delete_data_for_all_users_in_context',
@ -1044,7 +1044,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
}));
$manager = $this->getMockBuilder(\tool_dataprivacy\expired_contexts_manager::class)
->setMethods(['get_privacy_manager'])
->onlyMethods(['get_privacy_manager'])
->getMock();
$manager->method('get_privacy_manager')->willReturn($mockprivacymanager);
@ -1112,7 +1112,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$expiredcontext->save();
$mockprivacymanager = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods([
->onlyMethods([
'delete_data_for_user',
'delete_data_for_users_in_context',
'delete_data_for_all_users_in_context',
@ -1133,7 +1133,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
}));
$manager = $this->getMockBuilder(\tool_dataprivacy\expired_contexts_manager::class)
->setMethods(['get_privacy_manager'])
->onlyMethods(['get_privacy_manager'])
->getMock();
$manager->method('get_privacy_manager')->willReturn($mockprivacymanager);
@ -1208,7 +1208,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$expiredcontext->save();
$mockprivacymanager = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods([
->onlyMethods([
'delete_data_for_user',
'delete_data_for_users_in_context',
'delete_data_for_all_users_in_context',
@ -1229,7 +1229,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
}));
$manager = $this->getMockBuilder(\tool_dataprivacy\expired_contexts_manager::class)
->setMethods(['get_privacy_manager'])
->onlyMethods(['get_privacy_manager'])
->getMock();
$manager->method('get_privacy_manager')->willReturn($mockprivacymanager);
@ -1260,7 +1260,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$expiredcontext->save();
$mockprivacymanager = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods([
->onlyMethods([
'delete_data_for_user',
'delete_data_for_all_users_in_context',
])
@ -1269,7 +1269,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$mockprivacymanager->expects($this->never())->method('delete_data_for_all_users_in_context');
$manager = $this->getMockBuilder(\tool_dataprivacy\expired_contexts_manager::class)
->setMethods(['get_privacy_manager'])
->onlyMethods(['get_privacy_manager'])
->getMock();
$manager->set_progress(new \null_progress_trace());
@ -1299,7 +1299,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$expiredcontext->save();
$mockprivacymanager = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods([
->onlyMethods([
'delete_data_for_user',
'delete_data_for_all_users_in_context',
])
@ -1308,7 +1308,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$mockprivacymanager->expects($this->never())->method('delete_data_for_all_users_in_context');
$manager = $this->getMockBuilder(\tool_dataprivacy\expired_contexts_manager::class)
->setMethods(['get_privacy_manager'])
->onlyMethods(['get_privacy_manager'])
->getMock();
$manager->set_progress(new \null_progress_trace());
@ -1335,7 +1335,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$expiredcontext->save();
$mockprivacymanager = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods([
->onlyMethods([
'delete_data_for_user',
'delete_data_for_all_users_in_context',
])
@ -1344,7 +1344,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$mockprivacymanager->expects($this->never())->method('delete_data_for_all_users_in_context');
$manager = $this->getMockBuilder(\tool_dataprivacy\expired_contexts_manager::class)
->setMethods(['get_privacy_manager'])
->onlyMethods(['get_privacy_manager'])
->getMock();
$manager->set_progress(new \null_progress_trace());
@ -1382,7 +1382,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$expiredcontext->save();
$mockprivacymanager = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods([
->onlyMethods([
'delete_data_for_user',
'delete_data_for_all_users_in_context',
])
@ -1396,7 +1396,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
);
$manager = $this->getMockBuilder(\tool_dataprivacy\expired_contexts_manager::class)
->setMethods(['get_privacy_manager'])
->onlyMethods(['get_privacy_manager'])
->getMock();
$manager->set_progress(new \null_progress_trace());
@ -1442,7 +1442,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$expiredcontext->save();
$mockprivacymanager = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods([
->onlyMethods([
'delete_data_for_user',
'delete_data_for_all_users_in_context',
])
@ -1451,7 +1451,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$mockprivacymanager->expects($this->once())->method('delete_data_for_all_users_in_context');
$manager = $this->getMockBuilder(\tool_dataprivacy\expired_contexts_manager::class)
->setMethods(['get_privacy_manager'])
->onlyMethods(['get_privacy_manager'])
->getMock();
$manager->set_progress(new \null_progress_trace());
@ -1494,7 +1494,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$this->setUser();
$mockprivacymanager = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods([
->onlyMethods([
'delete_data_for_user',
'delete_data_for_all_users_in_context',
])
@ -1503,7 +1503,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$mockprivacymanager->expects($this->never())->method('delete_data_for_all_users_in_context');
$manager = $this->getMockBuilder(\tool_dataprivacy\expired_contexts_manager::class)
->setMethods(['get_privacy_manager'])
->onlyMethods(['get_privacy_manager'])
->getMock();
$manager->set_progress(new \null_progress_trace());
@ -1546,7 +1546,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
set_config('siteadmins', implode(',', $admins));
$mockprivacymanager = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods([
->onlyMethods([
'delete_data_for_user',
'delete_data_for_all_users_in_context',
])
@ -1555,7 +1555,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$mockprivacymanager->expects($this->never())->method('delete_data_for_all_users_in_context');
$manager = $this->getMockBuilder(\tool_dataprivacy\expired_contexts_manager::class)
->setMethods(['get_privacy_manager'])
->onlyMethods(['get_privacy_manager'])
->getMock();
$manager->set_progress(new \null_progress_trace());
@ -1600,7 +1600,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$expiredblockcontext->save();
$mockprivacymanager = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods([
->onlyMethods([
'delete_data_for_user',
'delete_data_for_all_users_in_context',
])
@ -1614,7 +1614,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
);
$manager = $this->getMockBuilder(\tool_dataprivacy\expired_contexts_manager::class)
->setMethods(['get_privacy_manager'])
->onlyMethods(['get_privacy_manager'])
->getMock();
$manager->set_progress(new \null_progress_trace());
@ -1653,7 +1653,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$expiredusercontext->save();
$mockprivacymanager = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods([
->onlyMethods([
'delete_data_for_user',
'delete_data_for_all_users_in_context',
])
@ -1667,7 +1667,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
);
$manager = $this->getMockBuilder(\tool_dataprivacy\expired_contexts_manager::class)
->setMethods(['get_privacy_manager'])
->onlyMethods(['get_privacy_manager'])
->getMock();
$manager->set_progress(new \null_progress_trace());
@ -1705,7 +1705,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$expiredcontext->save();
$mockprivacymanager = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods([
->onlyMethods([
'delete_data_for_user',
'delete_data_for_all_users_in_context',
])
@ -1714,7 +1714,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$mockprivacymanager->expects($this->never())->method('delete_data_for_all_users_in_context');
$manager = $this->getMockBuilder(\tool_dataprivacy\expired_contexts_manager::class)
->setMethods(['get_privacy_manager'])
->onlyMethods(['get_privacy_manager'])
->getMock();
$manager->set_progress(new \null_progress_trace());
$manager->method('get_privacy_manager')->willReturn($mockprivacymanager);
@ -1756,7 +1756,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$expiredcontext->save();
$mockprivacymanager = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods([
->onlyMethods([
'delete_data_for_user',
'delete_data_for_all_users_in_context',
])
@ -1765,7 +1765,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$mockprivacymanager->expects($this->never())->method('delete_data_for_all_users_in_context');
$manager = $this->getMockBuilder(\tool_dataprivacy\expired_contexts_manager::class)
->setMethods(['get_privacy_manager'])
->onlyMethods(['get_privacy_manager'])
->getMock();
$manager->set_progress(new \null_progress_trace());
@ -1814,7 +1814,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$expiredforumcontext->save();
$mockprivacymanager = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods([
->onlyMethods([
'delete_data_for_user',
'delete_data_for_all_users_in_context',
])
@ -1823,7 +1823,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$mockprivacymanager->expects($this->never())->method('delete_data_for_all_users_in_context');
$manager = $this->getMockBuilder(\tool_dataprivacy\expired_contexts_manager::class)
->setMethods(['get_privacy_manager'])
->onlyMethods(['get_privacy_manager'])
->getMock();
$manager->set_progress(new \null_progress_trace());
@ -1872,7 +1872,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
$expiredforumcontext->save();
$mockprivacymanager = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods([
->onlyMethods([
'delete_data_for_user',
'delete_data_for_all_users_in_context',
])
@ -1886,7 +1886,7 @@ class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
);
$manager = $this->getMockBuilder(\tool_dataprivacy\expired_contexts_manager::class)
->setMethods(['get_privacy_manager'])
->onlyMethods(['get_privacy_manager'])
->getMock();
$manager->set_progress(new \null_progress_trace());

View File

@ -42,7 +42,7 @@ class tool_dataprivacy_filtered_userlist_testcase extends advanced_testcase {
public function test_apply_expired_contexts_filters(array $initial, array $expired, array $unexpired, array $expected) {
$userlist = $this->getMockBuilder(\tool_dataprivacy\filtered_userlist::class)
->disableOriginalConstructor()
->setMethods(null)
->onlyMethods([])
->getMock();
$rc = new \ReflectionClass(\tool_dataprivacy\filtered_userlist::class);

View File

@ -42,7 +42,7 @@ class locale_testcase extends \advanced_testcase {
// - second setlocale() call which try to set new 'es' locale
// - third setlocale() call which restore locale.
$mock = $this->getMockBuilder(\tool_langimport\locale::class)
->setMethods(['set_locale'])
->onlyMethods(['set_locale'])
->getMock();
$mock->method('set_locale')->will($this->onConsecutiveCalls('en', 'es', 'en'));
@ -55,7 +55,7 @@ class locale_testcase extends \advanced_testcase {
// - second setlocale() call which fail to set new locale
// - third setlocale() call which restore locale.
$mock = $this->getMockBuilder(\tool_langimport\locale::class)
->setMethods(['set_locale'])
->onlyMethods(['set_locale'])
->getMock();
$mock->method('set_locale')->will($this->onConsecutiveCalls('en', false, 'en'));

View File

@ -43,7 +43,7 @@ class tool_monitor_subscription_testcase extends advanced_testcase {
$sub->name = 'My test rule';
$sub->courseid = 20;
$mockbuilder = $this->getMockBuilder('\tool_monitor\subscription');
$mockbuilder->setMethods(null);
$mockbuilder->onlyMethods([]);
$mockbuilder->setConstructorArgs(array($sub));
$this->subscription = $mockbuilder->getMock();
}

View File

@ -117,7 +117,7 @@ class step_testcase extends advanced_testcase {
*/
public function test_fetch() {
$step = $this->getMockBuilder(\tool_usertours\step::class)
->setMethods(['reload_from_record'])
->onlyMethods(['reload_from_record'])
->getMock()
;
@ -185,7 +185,7 @@ class step_testcase extends advanced_testcase {
*/
public function test_is_first_step($sortorder, $count, $isfirst, $islast) {
$step = $this->getMockBuilder(\tool_usertours\step::class)
->setMethods(['get_sortorder'])
->onlyMethods(['get_sortorder'])
->getMock();
$step->expects($this->once())
@ -207,11 +207,11 @@ class step_testcase extends advanced_testcase {
*/
public function test_is_last_step($sortorder, $count, $isfirst, $islast) {
$step = $this->getMockBuilder(\tool_usertours\step::class)
->setMethods(['get_sortorder', 'get_tour'])
->onlyMethods(['get_sortorder', 'get_tour'])
->getMock();
$tour = $this->getMockBuilder(\tool_usertours\tour::class)
->setMethods(['count_steps'])
->onlyMethods(['count_steps'])
->getMock();
$step->expects($this->once())
@ -362,7 +362,7 @@ class step_testcase extends advanced_testcase {
*/
public function test_get_config_valid_keys($values, $key, $default, $tourconfig, $isforced, $forcedvalue, $expected) {
$step = $this->getMockBuilder(\tool_usertours\step::class)
->setMethods(['get_target', 'get_targettype', 'get_tour'])
->onlyMethods(['get_target', 'get_targettype', 'get_tour'])
->getMock();
$rc = new \ReflectionClass(\tool_usertours\step::class);
@ -494,7 +494,7 @@ class step_testcase extends advanced_testcase {
*/
public function test_persist_non_dirty() {
$step = $this->getMockBuilder(\tool_usertours\step::class)
->setMethods([
->onlyMethods([
'to_record',
'reload',
])
@ -525,7 +525,7 @@ class step_testcase extends advanced_testcase {
// Mock the tour.
$step = $this->getMockBuilder(\tool_usertours\step::class)
->setMethods([
->onlyMethods([
'to_record',
'calculate_sortorder',
'reload',
@ -574,7 +574,7 @@ class step_testcase extends advanced_testcase {
// Mock the tour.
$step = $this->getMockBuilder(\tool_usertours\step::class)
->setMethods([
->onlyMethods([
'to_record',
'calculate_sortorder',
'reload',
@ -616,7 +616,7 @@ class step_testcase extends advanced_testcase {
// Mock the tour.
$step = $this->getMockBuilder(\tool_usertours\step::class)
->setMethods([
->onlyMethods([
'to_record',
'calculate_sortorder',
'reload',
@ -668,7 +668,7 @@ class step_testcase extends advanced_testcase {
// Mock the tour.
$step = $this->getMockBuilder(\tool_usertours\step::class)
->setMethods([
->onlyMethods([
'to_record',
'calculate_sortorder',
'reload',
@ -707,7 +707,7 @@ class step_testcase extends advanced_testcase {
*/
public function test_remove_non_persisted() {
$step = $this->getMockBuilder(\tool_usertours\step::class)
->setMethods(null)
->onlyMethods([])
->getMock()
;
@ -727,7 +727,7 @@ class step_testcase extends advanced_testcase {
$id = rand(1, 100);
$tour = $this->getMockBuilder(\tool_usertours\tour::class)
->setMethods([
->onlyMethods([
'reset_step_sortorder',
])
->getMock()
@ -738,7 +738,7 @@ class step_testcase extends advanced_testcase {
;
$step = $this->getMockBuilder(\tool_usertours\step::class)
->setMethods([
->onlyMethods([
'get_tour',
])
->getMock()

View File

@ -193,7 +193,7 @@ class tour_testcase extends advanced_testcase {
*/
public function test_persist_non_dirty() {
$tour = $this->getMockBuilder(tour::class)
->setMethods(['to_record'])
->onlyMethods(['to_record'])
->getMock()
;
@ -223,7 +223,7 @@ class tour_testcase extends advanced_testcase {
// Mock the tour.
$tour = $this->getMockBuilder(tour::class)
->setMethods([
->onlyMethods([
'to_record',
'reload',
])
@ -272,7 +272,7 @@ class tour_testcase extends advanced_testcase {
// Mock the tour.
$tour = $this->getMockBuilder(tour::class)
->setMethods([
->onlyMethods([
'to_record',
'reload',
])
@ -312,7 +312,7 @@ class tour_testcase extends advanced_testcase {
// Mock the tour.
$tour = $this->getMockBuilder(tour::class)
->setMethods([
->onlyMethods([
'to_record',
'reload',
])
@ -360,7 +360,7 @@ class tour_testcase extends advanced_testcase {
// Mock the tour.
$tour = $this->getMockBuilder(tour::class)
->setMethods([
->onlyMethods([
'to_record',
'reload',
])
@ -518,7 +518,7 @@ class tour_testcase extends advanced_testcase {
*/
public function test_remove_non_persisted() {
$tour = $this->getMockBuilder(tour::class)
->setMethods([
->onlyMethods([
'get_steps',
])
->getMock()
@ -544,7 +544,7 @@ class tour_testcase extends advanced_testcase {
$id = rand(1, 100);
$tour = $this->getMockBuilder(tour::class)
->setMethods([
->onlyMethods([
'get_steps',
])
->getMock()
@ -556,7 +556,7 @@ class tour_testcase extends advanced_testcase {
$rcp->setValue($tour, $id);
$step = $this->getMockBuilder(\tool_usertours\step::class)
->setMethods([
->onlyMethods([
'remove',
])
->getMock()
@ -683,7 +683,7 @@ class tour_testcase extends advanced_testcase {
$this->setAdminUser();
$tour = $this->getMockBuilder(tour::class)
->setMethods([
->onlyMethods([
'get_id',
'get_config',
'is_enabled',
@ -781,7 +781,7 @@ class tour_testcase extends advanced_testcase {
$this->setAdminUser();
$tour = $this->getMockBuilder(tour::class)
->setMethods([
->onlyMethods([
'get_config',
'set_config',
'get_id',
@ -839,7 +839,7 @@ class tour_testcase extends advanced_testcase {
*/
public function test_requested_user_reset() {
$tour = $this->getMockBuilder(tour::class)
->setMethods([
->onlyMethods([
'get_id',
])
->getMock()
@ -863,7 +863,7 @@ class tour_testcase extends advanced_testcase {
*/
public function test_mark_user_completed() {
$tour = $this->getMockBuilder(tour::class)
->setMethods([
->onlyMethods([
'get_id',
])
->getMock()
@ -1039,7 +1039,7 @@ class tour_testcase extends advanced_testcase {
*/
public function test_get_filter_values($fullconfig, $filtername, $expectedvalues) {
$tour = $this->getMockBuilder(tour::class)
->setMethods(['get_config'])
->onlyMethods(['get_config'])
->getMock();
$tour->expects($this->once())
@ -1097,7 +1097,7 @@ class tour_testcase extends advanced_testcase {
*/
public function test_set_filter_values_merge($currentvalues, $filtername, $newvalues, $expectedvalues) {
$tour = $this->getMockBuilder(tour::class)
->setMethods(['get_config', 'set_config'])
->onlyMethods(['get_config', 'set_config'])
->getMock();
$tour->expects($this->once())

View File

@ -76,7 +76,7 @@ class analytics_indicator_testcase extends advanced_testcase {
$indicator = new $indicatorclass();
$indicatormock = $this->getMockBuilder(get_class($indicator))
->setMethods(['calculate_sample'])
->onlyMethods(['calculate_sample'])
->getMock();
$indicatormock->method('calculate_sample')->willReturn($willreturn);
$this->expectException(coding_exception::class);

View File

@ -706,7 +706,7 @@ class core_analytics_prediction_testcase extends advanced_testcase {
$endtime = 321;
$sampleorigin = 'whatever';
$indicator = $this->getMockBuilder('test_indicator_max')->setMethods(['calculate_sample'])->getMock();
$indicator = $this->getMockBuilder('test_indicator_max')->onlyMethods(['calculate_sample'])->getMock();
$indicator->expects($this->never())->method('calculate_sample');
$existingcalcs = array(111 => 1, 222 => -1);

View File

@ -71,7 +71,7 @@ class core_backup_restore_gradebook_structure_step_testcase extends advanced_tes
*/
public function test_rewrite_step_backup_file_for_legacy_freeze($source, $expected) {
$restore = $this->getMockBuilder('\restore_gradebook_structure_step')
->setMethods(null)
->onlyMethods([])
->disableOriginalConstructor()
->getMock()
;

View File

@ -121,11 +121,11 @@ class block_rss_client_cron_testcase extends advanced_testcase {
// Run the scheduled task and have it fail.
$task = $this->getMockBuilder(\block_rss_client\task\refreshfeeds::class)
->setMethods(['fetch_feed'])
->onlyMethods(['fetch_feed'])
->getMock();
$piemock = $this->getMockBuilder(\moodle_simplepie::class)
->setMethods(['error'])
->onlyMethods(['error'])
->getMock();
$piemock->method('error')

View File

@ -83,7 +83,7 @@ class core_calendar_event_exporter_testcase extends advanced_testcase {
$class = \core_calendar\external\calendar_event_exporter::class;
$mock = $this->getMockBuilder($class)
->disableOriginalConstructor()
->setMethods(null)
->onlyMethods([])
->getMock();
$reflector = new ReflectionClass($class);
$method = $reflector->getMethod('get_timestamp_min_limit');
@ -140,7 +140,7 @@ class core_calendar_event_exporter_testcase extends advanced_testcase {
$class = \core_calendar\external\calendar_event_exporter::class;
$mock = $this->getMockBuilder($class)
->disableOriginalConstructor()
->setMethods(null)
->onlyMethods([])
->getMock();
$reflector = new ReflectionClass($class);
$method = $reflector->getMethod('get_timestamp_max_limit');

View File

@ -558,7 +558,7 @@ class core_contentbank_testcase extends advanced_testcase {
// Mock core_plugin_manager class and the method get_plugins_of_type.
$pluginmanager = $this->getMockBuilder(\core_plugin_manager::class)
->disableOriginalConstructor()
->setMethods(['get_plugins_of_type'])
->onlyMethods(['get_plugins_of_type'])
->getMock();
// Replace protected singletoninstance reference (core_plugin_manager property) with mock object.

View File

@ -56,7 +56,7 @@ class core_course_category_hooks_testcase extends \advanced_testcase {
// Setup mock object for \core_course_category.
// Disable original constructor, since we can't use it directly since it is private.
$mockcategory = $this->getMockBuilder(\core_course_category::class)
->setMethods(['get_plugins_callback_function'])
->onlyMethods(['get_plugins_callback_function'])
->disableOriginalConstructor()
->getMock();

View File

@ -59,7 +59,7 @@ class component_favourite_service_testcase extends advanced_testcase {
protected function get_mock_repository(array $mockstore) {
// This mock will just store data in an array.
$mockrepo = $this->getMockBuilder(\core_favourites\local\repository\favourite_repository_interface::class)
->setMethods([])
->onlyMethods([])
->getMock();
$mockrepo->expects($this->any())
->method('add')

View File

@ -59,7 +59,7 @@ class user_favourite_service_testcase extends advanced_testcase {
protected function get_mock_repository(array $mockstore) {
// This mock will just store data in an array.
$mockrepo = $this->getMockBuilder(\core_favourites\local\repository\favourite_repository_interface::class)
->setMethods([])
->onlyMethods([])
->getMock();
$mockrepo->expects($this->any())
->method('add')

View File

@ -52,9 +52,9 @@ class fileconverter_unoconv_converter_testcase extends advanced_testcase {
* If no methods are specified, only abstract functions are mocked.
* @return \fileconverter_unoconv\converter
*/
protected function get_testable_mock($mockedmethods = null) {
protected function get_testable_mock($mockedmethods = []) {
$converter = $this->getMockBuilder(\fileconverter_unoconv\converter::class)
->setMethods($mockedmethods)
->onlyMethods($mockedmethods)
->getMock();
return $converter;

View File

@ -47,7 +47,7 @@ class core_files_converter_testcase extends advanced_testcase {
*/
protected function get_testable_mock($mockedmethods = []) {
$converter = $this->getMockBuilder(\core_files\converter::class)
->setMethods($mockedmethods)
->onlyMethods($mockedmethods)
->getMockForAbstractClass();
return $converter;
@ -61,7 +61,7 @@ class core_files_converter_testcase extends advanced_testcase {
*/
protected function get_testable_conversion($mockedmethods = []) {
$conversion = $this->getMockBuilder(\core_files\conversion::class)
->setMethods($mockedmethods)
->onlyMethods($mockedmethods)
->setConstructorArgs([0, (object) []])
->getMock();
@ -77,7 +77,7 @@ class core_files_converter_testcase extends advanced_testcase {
*/
protected function get_mocked_converter($mockedmethods = []) {
$converter = $this->getMockBuilder(\core_files\converter_interface::class)
->setMethods($mockedmethods)
->onlyMethods($mockedmethods)
->getMockForAbstractClass();
return $converter;
@ -92,7 +92,7 @@ class core_files_converter_testcase extends advanced_testcase {
* If no methods are specified, only abstract functions are mocked.
* @return stored_file
*/
protected function get_stored_file($filecontent = 'content', $filename = null, $filerecord = [], $mockedmethods = null) {
protected function get_stored_file($filecontent = 'content', $filename = null, $filerecord = [], $mockedmethods = []) {
global $CFG;
$contenthash = sha1($filecontent);
@ -106,7 +106,7 @@ class core_files_converter_testcase extends advanced_testcase {
$filerecord['id'] = 42;
$file = $this->getMockBuilder(stored_file::class)
->setMethods($mockedmethods)
->onlyMethods($mockedmethods)
->setConstructorArgs([get_file_storage(), (object) $filerecord])
->getMock();
@ -145,7 +145,7 @@ class core_files_converter_testcase extends advanced_testcase {
*/
protected function get_file_storage_mock($mockedmethods = []) {
$fs = $this->getMockBuilder(\file_storage::class)
->setMethods($mockedmethods)
->onlyMethods($mockedmethods)
->disableOriginalConstructor()
->getMock();
@ -248,7 +248,7 @@ class core_files_converter_testcase extends advanced_testcase {
*/
public function test_get_document_converter_classes_plugin_class_requirements_not_met() {
$plugin = $this->getMockBuilder(\core_file_converter_requirements_not_met_test::class)
->setMethods()
->onlyMethods([])
->getMock();
$converter = $this->get_testable_mock(['get_enabled_plugins']);
@ -267,7 +267,7 @@ class core_files_converter_testcase extends advanced_testcase {
*/
public function test_get_document_converter_classes_plugin_class_met_not_supported() {
$plugin = $this->getMockBuilder(\core_file_converter_type_not_supported_test::class)
->setMethods()
->onlyMethods([])
->getMock();
$converter = $this->get_testable_mock(['get_enabled_plugins']);
@ -286,7 +286,7 @@ class core_files_converter_testcase extends advanced_testcase {
*/
public function test_get_document_converter_classes_plugin_class_met_and_supported() {
$plugin = $this->getMockBuilder(\core_file_converter_type_supported_test::class)
->setMethods()
->onlyMethods([])
->getMock();
$classname = get_class($plugin);

View File

@ -44,7 +44,7 @@ class antivirus_clamav_scanner_testcase extends advanced_testcase {
public function test_scan_file_not_exists() {
$antivirus = $this->getMockBuilder('\antivirus_clamav\scanner')
->setMethods(array('scan_file_execute_commandline', 'message_admins'))
->onlyMethods(array('scan_file_execute_commandline', 'message_admins'))
->getMock();
// Test specifying file that does not exist.
@ -63,7 +63,7 @@ class antivirus_clamav_scanner_testcase extends advanced_testcase {
'get_config',
);
$antivirus = $this->getMockBuilder('\antivirus_clamav\scanner')
->setMethods($methods)
->onlyMethods($methods)
->getMock();
// Initiate mock scanning with configuration setting to use commandline.
$configmap = array(array('runningmethod', 'commandline'));
@ -104,7 +104,7 @@ class antivirus_clamav_scanner_testcase extends advanced_testcase {
'get_config',
);
$antivirus = $this->getMockBuilder('\antivirus_clamav\scanner')
->setMethods($methods)
->onlyMethods($methods)
->getMock();
// Initiate mock scanning with configuration setting to use commandline.
$configmap = array(array('runningmethod', 'commandline'));
@ -146,7 +146,7 @@ class antivirus_clamav_scanner_testcase extends advanced_testcase {
'get_scanning_notice',
);
$antivirus = $this->getMockBuilder('\antivirus_clamav\scanner')
->setMethods($methods)
->onlyMethods($methods)
->getMock();
// Configure scan_file_execute_commandline and scan_file_execute_socket
@ -193,7 +193,7 @@ class antivirus_clamav_scanner_testcase extends advanced_testcase {
'get_scanning_notice',
);
$antivirus = $this->getMockBuilder('\antivirus_clamav\scanner')
->setMethods($methods)
->onlyMethods($methods)
->getMock();
// Configure scan_file_execute_commandline and scan_file_execute_socket
@ -242,7 +242,7 @@ class antivirus_clamav_scanner_testcase extends advanced_testcase {
'get_config',
'get_scanning_notice',
);
$antivirus = $this->getMockBuilder('\antivirus_clamav\scanner')->setMethods($methods)->getMock();
$antivirus = $this->getMockBuilder('\antivirus_clamav\scanner')->onlyMethods($methods)->getMock();
// Configure scan_file_execute_commandline and scan_file_execute_unixsocket
// method stubs to behave as if there is a scanning error (SCAN_RESULT_ERROR).
@ -273,7 +273,7 @@ class antivirus_clamav_scanner_testcase extends advanced_testcase {
'get_config',
);
$antivirus = $this->getMockBuilder('\antivirus_clamav\scanner')
->setMethods($methods)
->onlyMethods($methods)
->getMock();
// Initiate mock scanning with configuration setting to use unixsocket.
$configmap = array(array('runningmethod', 'unixsocket'));
@ -307,7 +307,7 @@ class antivirus_clamav_scanner_testcase extends advanced_testcase {
'get_config',
);
$antivirus = $this->getMockBuilder('\antivirus_clamav\scanner')
->setMethods($methods)
->onlyMethods($methods)
->getMock();
// Initiate mock scanning with configuration setting to use unixsocket.
$configmap = array(array('runningmethod', 'unixsocket'));
@ -342,7 +342,7 @@ class antivirus_clamav_scanner_testcase extends advanced_testcase {
'get_scanning_notice',
);
$antivirus = $this->getMockBuilder('\antivirus_clamav\scanner')
->setMethods($methods)
->onlyMethods($methods)
->getMock();
// Initiate mock scanning with configuration setting to do nothing on
// scanning error and using unixsocket.
@ -380,7 +380,7 @@ class antivirus_clamav_scanner_testcase extends advanced_testcase {
'get_scanning_notice',
);
$antivirus = $this->getMockBuilder('\antivirus_clamav\scanner')
->setMethods($methods)
->onlyMethods($methods)
->getMock();
// Initiate mock scanning with configuration setting to act like virus on

View File

@ -99,14 +99,14 @@ class core_files_file_system_filedir_testcase extends advanced_testcase {
* If no methods are specified, only abstract functions are mocked.
* @return stored_file
*/
protected function get_stored_file($filecontent, $filename = null, $mockedmethods = null) {
protected function get_stored_file($filecontent, $filename = null, $mockedmethods = []) {
$contenthash = file_storage::hash_from_string($filecontent);
if (empty($filename)) {
$filename = $contenthash;
}
$file = $this->getMockBuilder(stored_file::class)
->setMethods($mockedmethods)
->onlyMethods($mockedmethods)
->setConstructorArgs([
get_file_storage(),
(object) [
@ -129,7 +129,7 @@ class core_files_file_system_filedir_testcase extends advanced_testcase {
*/
protected function get_testable_mock($mockedmethods = []) {
$fs = $this->getMockBuilder(file_system_filedir::class)
->setMethods($mockedmethods)
->onlyMethods($mockedmethods)
->getMock();
return $fs;
@ -321,7 +321,7 @@ class core_files_file_system_filedir_testcase extends advanced_testcase {
$file = $this->getMockBuilder('stored_file')
->disableOriginalConstructor()
->setMethods([
->onlyMethods([
'sync_external_file',
'get_contenthash',
])
@ -441,7 +441,7 @@ class core_files_file_system_filedir_testcase extends advanced_testcase {
$fs = $this->getMockBuilder(file_system_filedir::class)
->disableOriginalConstructor()
->setMethods([
->onlyMethods([
'get_local_path_from_storedfile',
])
->getMock();
@ -997,7 +997,7 @@ class core_files_file_system_filedir_testcase extends advanced_testcase {
global $DB;
$DB = $this->getMockBuilder(\moodle_database::class)
->setMethods(['record_exists'])
->onlyMethods(['record_exists'])
->getMockForAbstractClass();
$DB->expects($this->never())
@ -1031,7 +1031,7 @@ class core_files_file_system_filedir_testcase extends advanced_testcase {
$vfileroot = $this->setup_vfile_root($filedircontent);
$DB = $this->getMockBuilder(\moodle_database::class)
->setMethods(['record_exists'])
->onlyMethods(['record_exists'])
->getMockForAbstractClass();
$DB->method('record_exists')->willReturn(true);
@ -1064,7 +1064,7 @@ class core_files_file_system_filedir_testcase extends advanced_testcase {
$vfileroot = $this->setup_vfile_root($filedircontent);
$DB = $this->getMockBuilder(\moodle_database::class)
->setMethods(['record_exists'])
->onlyMethods(['record_exists'])
->getMockForAbstractClass();
$DB->method('record_exists')->willReturn(false);

View File

@ -70,14 +70,14 @@ class core_files_file_system_testcase extends advanced_testcase {
* If no methods are specified, only abstract functions are mocked.
* @return stored_file
*/
protected function get_stored_file($filecontent, $filename = null, $mockedmethods = null) {
protected function get_stored_file($filecontent, $filename = null, $mockedmethods = []) {
$contenthash = file_storage::hash_from_string($filecontent);
if (empty($filename)) {
$filename = $contenthash;
}
$file = $this->getMockBuilder(stored_file::class)
->setMethods($mockedmethods)
->onlyMethods($mockedmethods)
->setConstructorArgs([
get_file_storage(),
(object) [
@ -100,7 +100,7 @@ class core_files_file_system_testcase extends advanced_testcase {
*/
protected function get_testable_mock($mockedmethods = []) {
$fs = $this->getMockBuilder(file_system::class)
->setMethods($mockedmethods)
->onlyMethods($mockedmethods)
->getMockForAbstractClass();
return $fs;
@ -514,7 +514,7 @@ class core_files_file_system_testcase extends advanced_testcase {
$contenthash = file_storage::hash_from_string($filecontent);
$DB = $this->getMockBuilder(\moodle_database::class)
->setMethods(['record_exists'])
->onlyMethods(['record_exists'])
->getMockForAbstractClass();
$DB->method('record_exists')->willReturn(true);
@ -538,7 +538,7 @@ class core_files_file_system_testcase extends advanced_testcase {
$contenthash = file_storage::hash_from_string($filecontent);
$DB = $this->getMockBuilder(\moodle_database::class)
->setMethods(['record_exists'])
->onlyMethods(['record_exists'])
->getMockForAbstractClass();
$DB->method('record_exists')->willReturn(false);
@ -615,7 +615,7 @@ class core_files_file_system_testcase extends advanced_testcase {
->willReturn(__FILE__);
$packer = $this->getMockBuilder(file_packer::class)
->setMethods(['list_files'])
->onlyMethods(['list_files'])
->getMockForAbstractClass();
$packer->expects($this->once())
@ -648,7 +648,7 @@ class core_files_file_system_testcase extends advanced_testcase {
->willReturn(__FILE__);
$packer = $this->getMockBuilder(file_packer::class)
->setMethods(['extract_to_pathname'])
->onlyMethods(['extract_to_pathname'])
->getMockForAbstractClass();
$packer->expects($this->once())
@ -681,7 +681,7 @@ class core_files_file_system_testcase extends advanced_testcase {
->willReturn(__FILE__);
$packer = $this->getMockBuilder(file_packer::class)
->setMethods(['extract_to_storage'])
->onlyMethods(['extract_to_storage'])
->getMockForAbstractClass();
$packer->expects($this->once())
@ -720,7 +720,7 @@ class core_files_file_system_testcase extends advanced_testcase {
->willReturn(__FILE__);
$archive = $this->getMockBuilder(file_archive::class)
->setMethods([
->onlyMethods([
'add_directory',
'add_file_from_pathname',
])
@ -757,7 +757,7 @@ class core_files_file_system_testcase extends advanced_testcase {
->willReturn($filepath);
$archive = $this->getMockBuilder(file_archive::class)
->setMethods([
->onlyMethods([
'add_directory',
'add_file_from_pathname',
])

View File

@ -135,7 +135,7 @@ class filterset_test extends advanced_testcase {
public function test_add_filter_validated_type(): void {
$namefilter = $this->getMockBuilder(filter::class)
->setConstructorArgs(['name'])
->setMethods(null)
->onlyMethods([])
->getMock();
$namefilter->add_filter_value('rosie');
@ -188,7 +188,7 @@ class filterset_test extends advanced_testcase {
// Add a filter to the list.
// This is the 'name' filter.
$namefilter = $this->getMockBuilder(filter::class)
->setMethods(null)
->onlyMethods([])
->setConstructorArgs([$filtername])
->getMock();
@ -207,7 +207,7 @@ class filterset_test extends advanced_testcase {
public function test_add_filter_from_params(): void {
$filtername = "name";
$otherfilter = $this->getMockBuilder(filter::class)
->setMethods(null)
->onlyMethods([])
->setConstructorArgs([$filtername])
->getMock();
@ -254,7 +254,7 @@ class filterset_test extends advanced_testcase {
public function test_add_filter_from_params_invalid(): void {
$filtername = "name";
$otherfilter = $this->getMockBuilder(filter::class)
->setMethods(null)
->onlyMethods([])
->setConstructorArgs([$filtername])
->getMock();

View File

@ -4233,7 +4233,7 @@ class core_accesslib_testcase extends advanced_testcase {
public function test_is_parent_of(string $contextpath, string $testpath, bool $testself, bool $expected): void {
$context = $this->getMockBuilder(\context::class)
->disableOriginalConstructor()
->setMethods([
->onlyMethods([
'get_url',
'get_capabilities',
])
@ -4245,7 +4245,7 @@ class core_accesslib_testcase extends advanced_testcase {
$comparisoncontext = $this->getMockBuilder(\context::class)
->disableOriginalConstructor()
->setMethods([
->onlyMethods([
'get_url',
'get_capabilities',
])
@ -4335,7 +4335,7 @@ class core_accesslib_testcase extends advanced_testcase {
public function test_is_child_of(string $contextpath, string $testpath, bool $testself, bool $expected): void {
$context = $this->getMockBuilder(\context::class)
->disableOriginalConstructor()
->setMethods([
->onlyMethods([
'get_url',
'get_capabilities',
])
@ -4347,7 +4347,7 @@ class core_accesslib_testcase extends advanced_testcase {
$comparisoncontext = $this->getMockBuilder(\context::class)
->disableOriginalConstructor()
->setMethods([
->onlyMethods([
'get_url',
'get_capabilities',
])

View File

@ -129,7 +129,7 @@ class core_completionlib_testcase extends advanced_testcase {
$this->mock_setup();
$mockbuilder = $this->getMockBuilder('completion_info');
$mockbuilder->setMethods(array('is_enabled', 'get_data', 'internal_get_state', 'internal_set_data',
$mockbuilder->onlyMethods(array('is_enabled', 'get_data', 'internal_get_state', 'internal_set_data',
'user_can_override_completion'));
$mockbuilder->setConstructorArgs(array((object)array('id' => 42)));
$cm = (object)array('id'=>13, 'course'=>42);
@ -453,7 +453,7 @@ class core_completionlib_testcase extends advanced_testcase {
$this->mock_setup();
$mockbuilder = $this->getMockBuilder('completion_info');
$mockbuilder->setMethods(array('is_enabled', 'get_data', 'internal_set_data', 'update_state'));
$mockbuilder->onlyMethods(array('is_enabled', 'get_data', 'internal_set_data', 'update_state'));
$mockbuilder->setConstructorArgs(array((object)array('id' => 42)));
$cm = (object)array('id'=>13, 'course'=>42);
@ -542,7 +542,7 @@ class core_completionlib_testcase extends advanced_testcase {
$this->mock_setup();
$mockbuilder = $this->getMockBuilder('completion_info');
$mockbuilder->setMethods(array('delete_all_state', 'get_tracked_users', 'update_state'));
$mockbuilder->onlyMethods(array('delete_all_state', 'get_tracked_users', 'update_state'));
$mockbuilder->setConstructorArgs(array((object)array('id' => 42)));
$c = $mockbuilder->getMock();
@ -756,7 +756,7 @@ class core_completionlib_testcase extends advanced_testcase {
$this->mock_setup();
$mockbuilder = $this->getMockBuilder('completion_info');
$mockbuilder->setMethods(array('get_tracked_users'));
$mockbuilder->onlyMethods(array('get_tracked_users'));
$mockbuilder->setConstructorArgs(array((object)array('id' => 42)));
$c = $mockbuilder->getMock();
@ -790,7 +790,7 @@ class core_completionlib_testcase extends advanced_testcase {
$this->mock_setup();
$mockbuilder = $this->getMockBuilder('completion_info');
$mockbuilder->setMethods(array('get_tracked_users'));
$mockbuilder->onlyMethods(array('get_tracked_users'));
$mockbuilder->setConstructorArgs(array((object)array('id' => 42)));
$c = $mockbuilder->getMock();
@ -844,7 +844,7 @@ class core_completionlib_testcase extends advanced_testcase {
$this->mock_setup();
$mockbuilder = $this->getMockBuilder('completion_info');
$mockbuilder->setMethods(array('is_enabled', 'update_state'));
$mockbuilder->onlyMethods(array('is_enabled', 'update_state'));
$mockbuilder->setConstructorArgs(array((object)array('id' => 42)));
$cm = (object)array('course'=>42, 'id'=>13, 'completion'=>0, 'completiongradeitemnumber'=>null);

View File

@ -224,7 +224,7 @@ class exportable_filearea_test extends advanced_testcase {
): exported_item {
$archive = $this->getMockBuilder(zipwriter::class)
->setConstructorArgs([$this->getMockBuilder(\ZipStream\ZipStream::class)->getmock()])
->setMethods([
->onlyMethods([
'add_file_from_stored_file',
'is_file_in_archive',
])

View File

@ -209,7 +209,7 @@ class exportable_stored_file_test extends advanced_testcase {
): void {
$archive = $this->getMockBuilder(zipwriter::class)
->setConstructorArgs([$this->getMockBuilder(\ZipStream\ZipStream::class)->getmock()])
->setMethods([
->onlyMethods([
'add_file_from_stored_file',
])
->getMock();

View File

@ -309,7 +309,7 @@ EOF;
): void {
$archive = $this->getMockBuilder(zipwriter::class)
->setConstructorArgs([$this->getMockBuilder(\ZipStream\ZipStream::class)->getmock()])
->setMethods([
->onlyMethods([
'is_file_in_archive',
'add_file_from_string',
'add_file_from_stored_file',
@ -357,7 +357,7 @@ EOF;
): void {
$archive = $this->getMockBuilder(zipwriter::class)
->setConstructorArgs([$this->getMockBuilder(\ZipStream\ZipStream::class)->getmock()])
->setMethods([
->onlyMethods([
'add_file_from_stored_file',
'add_file_from_string',
'add_file_from_template',

View File

@ -149,7 +149,7 @@ class course_exporter_test extends advanced_testcase {
protected function get_mocked_zipwriter(?array $methods = []): zipwriter {
return $this->getMockBuilder(zipwriter::class)
->setConstructorArgs([$this->getMockBuilder(\ZipStream\ZipStream::class)->getmock()])
->setMethods($methods)
->onlyMethods($methods)
->getMock();
}
}

View File

@ -48,7 +48,7 @@ class core_curl_security_helper_testcase extends advanced_testcase {
public function test_curl_security_helper_url_is_blocked($dns, $url, $blockedhosts, $allowedports, $expected) {
$this->resetAfterTest(true);
$helper = $this->getMockBuilder('\core\files\curl_security_helper')
->setMethods(['get_host_list_by_name'])
->onlyMethods(['get_host_list_by_name'])
->getMock();
// Override the get host list method to return hard coded values based on a mapping provided by $dns.

View File

@ -73,7 +73,7 @@ class h5p_get_content_types_task_testcase extends advanced_testcase {
// Mock implementation of \core\task\h5p_get_content_types_task::get_core to avoid external systems.
$mocktask = $this->getMockBuilder(\core\task\h5p_get_content_types_task::class)
->setMethods(['get_core'])
->onlyMethods(['get_core'])
->getMock();
$mocktask->expects($this->any())

View File

@ -104,7 +104,7 @@ class task_database_logger_testcase extends advanced_testcase {
file_put_contents($logpath, 'Example content');
$task = $this->getMockBuilder(\core\task\adhoc_task::class)
->setMethods(['get_component', 'execute'])
->onlyMethods(['get_component', 'execute'])
->getMock();
$task->method('get_component')->willReturn('core_test');
@ -165,7 +165,7 @@ class task_database_logger_testcase extends advanced_testcase {
file_put_contents($logpath, 'Example content');
$task = $this->getMockBuilder(\core\task\adhoc_task::class)
->setMethods(['get_component', 'execute'])
->onlyMethods(['get_component', 'execute'])
->getMock();
$task->method('get_component')->willReturn('core_test');
@ -197,7 +197,7 @@ class task_database_logger_testcase extends advanced_testcase {
file_put_contents($logpath, 'Example content');
$task = $this->getMockBuilder(\core\task\adhoc_task::class)
->setMethods(['get_component', 'execute', 'get_userid'])
->onlyMethods(['get_component', 'execute', 'get_userid'])
->getMock();
$task->method('get_component')->willReturn('core_test');

View File

@ -914,7 +914,7 @@ class mod_data_lib_testcase extends advanced_testcase {
// Note: Use the actual test class here rather than the abstract because are testing concrete methods.
$this->DB = $DB;
$DB = $this->getMockBuilder(get_class($DB))
->setMethods(['set_field'])
->onlyMethods(['set_field'])
->getMock();
$DB->expects($this->exactly((int) $expectupdate))

View File

@ -330,7 +330,7 @@ class quizacces_seb_access_manager_testcase extends advanced_testcase {
public function test_should_validate_basic_header($type, $expected) {
$accessmanager = $this->getMockBuilder(access_manager::class)
->disableOriginalConstructor()
->setMethods(['get_seb_use_type'])
->onlyMethods(['get_seb_use_type'])
->getMock();
$accessmanager->method('get_seb_use_type')->willReturn($type);
@ -364,7 +364,7 @@ class quizacces_seb_access_manager_testcase extends advanced_testcase {
public function test_should_validate_config_key($type, $expected) {
$accessmanager = $this->getMockBuilder(access_manager::class)
->disableOriginalConstructor()
->setMethods(['get_seb_use_type'])
->onlyMethods(['get_seb_use_type'])
->getMock();
$accessmanager->method('get_seb_use_type')->willReturn($type);
@ -397,7 +397,7 @@ class quizacces_seb_access_manager_testcase extends advanced_testcase {
public function test_should_validate_browser_exam_key($type, $expected) {
$accessmanager = $this->getMockBuilder(access_manager::class)
->disableOriginalConstructor()
->setMethods(['get_seb_use_type'])
->onlyMethods(['get_seb_use_type'])
->getMock();
$accessmanager->method('get_seb_use_type')->willReturn($type);

View File

@ -57,7 +57,7 @@ class privacy_manager_testcase extends advanced_testcase {
*/
protected function get_mock_manager_with_core_components($componentnames) {
$mock = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods(['get_component_list'])
->onlyMethods(['get_component_list'])
->getMock();
$mock->expects($this->any())
->method('get_component_list')
@ -336,7 +336,7 @@ class privacy_manager_testcase extends advanced_testcase {
$mockman = $this->get_mock_manager_with_core_components(['mod_component_broken', 'mod_component_a']);
$observer = $this->getMockBuilder(\core_privacy\manager_observer::class)
->setMethods(['handle_component_failure'])
->onlyMethods(['handle_component_failure'])
->getMock();
$mockman->set_observer($observer);
@ -374,7 +374,7 @@ class privacy_manager_testcase extends advanced_testcase {
$contextid = $context->id;
$observer = $this->getMockBuilder(\core_privacy\manager_observer::class)
->setMethods(['handle_component_failure'])
->onlyMethods(['handle_component_failure'])
->getMock();
$mockman->set_observer($observer);
@ -409,7 +409,7 @@ class privacy_manager_testcase extends advanced_testcase {
$contextid = $context->id;
$observer = $this->getMockBuilder(\core_privacy\manager_observer::class)
->setMethods(['handle_component_failure'])
->onlyMethods(['handle_component_failure'])
->getMock();
$mockman->set_observer($observer);
@ -443,7 +443,7 @@ class privacy_manager_testcase extends advanced_testcase {
$context = \context_system::instance();
$observer = $this->getMockBuilder(\core_privacy\manager_observer::class)
->setMethods(['handle_component_failure'])
->onlyMethods(['handle_component_failure'])
->getMock();
$mockman->set_observer($observer);
@ -473,7 +473,7 @@ class privacy_manager_testcase extends advanced_testcase {
$context = \context_system::instance();
$observer = $this->getMockBuilder(\core_privacy\manager_observer::class)
->setMethods(['handle_component_failure'])
->onlyMethods(['handle_component_failure'])
->getMock();
$mockman->set_observer($observer);

View File

@ -234,7 +234,7 @@ class sitepolicy_test extends advanced_testcase {
require_once($CFG->dirroot.'/privacy/tests/fixtures/mock_sitepolicy_handler.php');
$mock = $this->getMockBuilder(\core_privacy\local\sitepolicy\manager::class)
->setMethods(['get_all_handlers'])
->onlyMethods(['get_all_handlers'])
->getMock();
$mock->expects($this->any())
->method('get_all_handlers')

View File

@ -523,7 +523,7 @@ class tests_content_writer_test extends advanced_testcase {
$contenthash = file_storage::hash_from_string($filecontent);
$file = $this->getMockBuilder(stored_file::class)
->setMethods(null)
->onlyMethods([])
->setConstructorArgs([
get_file_storage(),
(object) [

View File

@ -83,7 +83,7 @@ class repository_dropbox_api_testcase extends advanced_testcase {
public function test_has_additional_results($result, $expected) {
$mock = $this->getMockBuilder(\repository_dropbox\dropbox::class)
->disableOriginalConstructor()
->setMethods(null)
->onlyMethods([])
->getMock();
$this->assertEquals($expected, $mock->has_additional_results($result));
@ -159,7 +159,7 @@ class repository_dropbox_api_testcase extends advanced_testcase {
public function test_check_and_handle_api_errors($info, $data, $exception, $exceptionmessage) {
$mock = $this->getMockBuilder(\repository_dropbox\dropbox::class)
->disableOriginalConstructor()
->setMethods(null)
->onlyMethods([])
->getMock();
$mock->info = $info;
@ -254,7 +254,7 @@ class repository_dropbox_api_testcase extends advanced_testcase {
public function test_supports_thumbnail($entry, $expected) {
$mock = $this->getMockBuilder(\repository_dropbox\dropbox::class)
->disableOriginalConstructor()
->setMethods(null)
->onlyMethods([])
->getMock();
$this->assertEquals($expected, $mock->supports_thumbnail($entry));
@ -266,7 +266,7 @@ class repository_dropbox_api_testcase extends advanced_testcase {
public function test_logout_revocation() {
$mock = $this->getMockBuilder(\repository_dropbox\dropbox::class)
->disableOriginalConstructor()
->setMethods(['fetch_dropbox_data'])
->onlyMethods(['fetch_dropbox_data'])
->getMock();
$mock->expects($this->once())
@ -282,7 +282,7 @@ class repository_dropbox_api_testcase extends advanced_testcase {
public function test_logout_revocation_catch_auth_exception() {
$mock = $this->getMockBuilder(\repository_dropbox\dropbox::class)
->disableOriginalConstructor()
->setMethods(['fetch_dropbox_data'])
->onlyMethods(['fetch_dropbox_data'])
->getMock();
$mock->expects($this->once())
@ -298,7 +298,7 @@ class repository_dropbox_api_testcase extends advanced_testcase {
public function test_logout_revocation_does_not_catch_other_exceptions() {
$mock = $this->getMockBuilder(\repository_dropbox\dropbox::class)
->disableOriginalConstructor()
->setMethods(['fetch_dropbox_data'])
->onlyMethods(['fetch_dropbox_data'])
->getMock();
$mock->expects($this->once())
@ -315,7 +315,7 @@ class repository_dropbox_api_testcase extends advanced_testcase {
public function test_fetch_dropbox_data_endpoint() {
$mock = $this->getMockBuilder(\repository_dropbox\dropbox::class)
->disableOriginalConstructor()
->setMethods([
->onlyMethods([
'request',
'get_api_endpoint',
'get_content_endpoint',
@ -350,7 +350,7 @@ class repository_dropbox_api_testcase extends advanced_testcase {
public function test_fetch_dropbox_data_postfields_null() {
$mock = $this->getMockBuilder(\repository_dropbox\dropbox::class)
->disableOriginalConstructor()
->setMethods([
->onlyMethods([
'request',
])
->getMock();
@ -377,7 +377,7 @@ class repository_dropbox_api_testcase extends advanced_testcase {
public function test_fetch_dropbox_data_postfields_data() {
$mock = $this->getMockBuilder(\repository_dropbox\dropbox::class)
->disableOriginalConstructor()
->setMethods([
->onlyMethods([
'request',
])
->getMock();
@ -405,7 +405,7 @@ class repository_dropbox_api_testcase extends advanced_testcase {
public function test_fetch_dropbox_data_recurse_on_additional_records() {
$mock = $this->getMockBuilder(\repository_dropbox\dropbox::class)
->disableOriginalConstructor()
->setMethods([
->onlyMethods([
'request',
'get_api_endpoint',
])
@ -456,7 +456,7 @@ class repository_dropbox_api_testcase extends advanced_testcase {
public function test_fetch_dropbox_content() {
$mock = $this->getMockBuilder(\repository_dropbox\dropbox::class)
->disableOriginalConstructor()
->setMethods([
->onlyMethods([
'request',
'setHeader',
'get_content_endpoint',
@ -514,7 +514,7 @@ class repository_dropbox_api_testcase extends advanced_testcase {
public function test_get_file_share_info_existing() {
$mock = $this->getMockBuilder(\repository_dropbox\dropbox::class)
->disableOriginalConstructor()
->setMethods([
->onlyMethods([
'fetch_dropbox_data',
'normalize_file_share_info',
])
@ -547,7 +547,7 @@ class repository_dropbox_api_testcase extends advanced_testcase {
public function test_get_file_share_info_new() {
$mock = $this->getMockBuilder(\repository_dropbox\dropbox::class)
->disableOriginalConstructor()
->setMethods([
->onlyMethods([
'fetch_dropbox_data',
'normalize_file_share_info',
])
@ -588,7 +588,7 @@ class repository_dropbox_api_testcase extends advanced_testcase {
public function test_get_file_share_info_new_failure() {
$mock = $this->getMockBuilder(\repository_dropbox\dropbox::class)
->disableOriginalConstructor()
->setMethods([
->onlyMethods([
'fetch_dropbox_data',
'normalize_file_share_info',
])

View File

@ -42,7 +42,7 @@ class search_area_category_testcase extends advanced_testcase {
protected function get_mocked_area($areaid) {
$builder = $this->getMockBuilder('\core_search\base');
$builder->disableOriginalConstructor();
$builder->setMethods(array('get_area_id'));
$builder->onlyMethods(array('get_area_id'));
$area = $builder->getMockForAbstractClass();
$area->method('get_area_id')->willReturn($areaid);

View File

@ -163,7 +163,7 @@ class search_base_activity_testcase extends advanced_testcase {
// with required methods stubbed.
$builder = $this->getMockBuilder('\core_search\base_activity');
$builder->disableOriginalConstructor();
$builder->setMethods(array('get_module_name', 'get_component_name'));
$builder->onlyMethods(array('get_module_name', 'get_component_name'));
$stub = $builder->getMockForAbstractClass();
$stub->method('get_module_name')->willReturn($module);
$stub->method('get_component_name')->willReturn($component);
@ -380,7 +380,7 @@ class search_base_activity_testcase extends advanced_testcase {
public function test_get_doc_icon() {
$baseactivity = $this->getMockBuilder('\core_search\base_activity')
->disableOriginalConstructor()
->setMethods(array('get_module_name'))
->onlyMethods(array('get_module_name'))
->getMockForAbstractClass();
$baseactivity->method('get_module_name')->willReturn('test_activity');

View File

@ -115,7 +115,7 @@ class search_base_testcase extends advanced_testcase {
// with required methods stubbed.
$builder = $this->getMockBuilder('\core_search\base');
$builder->disableOriginalConstructor();
$builder->setMethods(array('get_search_fileareas', 'get_component_name'));
$builder->onlyMethods(array('get_search_fileareas', 'get_component_name'));
$stub = $builder->getMockForAbstractClass();
$stub->method('get_search_fileareas')->willReturn(array($filearea));
$stub->method('get_component_name')->willReturn($component);

View File

@ -61,7 +61,7 @@ class webservice_xmlrpc_locallib_testcase extends advanced_testcase {
public function test_prepare_response($returnsdesc, $returns, $expected) {
$server = $this->getMockBuilder('webservice_xmlrpc_server')
->disableOriginalConstructor()
->setMethods(null)
->onlyMethods([])
->getMock();
$rc = new \ReflectionClass('webservice_xmlrpc_server');
@ -97,7 +97,7 @@ class webservice_xmlrpc_locallib_testcase extends advanced_testcase {
public function test_generate_error($exception, $code, $expected) {
$server = $this->getMockBuilder('webservice_xmlrpc_server')
->disableOriginalConstructor()
->setMethods(null)
->onlyMethods([])
->getMock();
$rc = new \ReflectionClass('webservice_xmlrpc_server');

View File

@ -57,7 +57,7 @@ class xmlrpc_server_test extends advanced_testcase {
*/
public function test_parse_request($input, $expectfunction, $expectparams) {
$server = $this->getMockBuilder('\webservice_xmlrpc_server')
->setMethods(['fetch_input_content'])
->onlyMethods(['fetch_input_content'])
->disableOriginalConstructor()
->getMock();