Skip to content

Commit

Permalink
MDL-71036 phpunit: Mock->setMethods() silently deprecated
Browse files Browse the repository at this point in the history
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: sebastianbergmann/phpunit#3770
  • Loading branch information
stronk7 committed Mar 11, 2021
1 parent 8a14a7b commit 81407f1
Show file tree
Hide file tree
Showing 42 changed files with 181 additions and 181 deletions.
14 changes: 7 additions & 7 deletions admin/tool/behat/tests/manager_util_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private function get_behat_config_util($behatconfigutil, $notheme = false) {
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();

Expand Down Expand Up @@ -188,7 +188,7 @@ public function test_get_config_file_contents_with_single_run() {
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();

Expand Down Expand Up @@ -242,7 +242,7 @@ public function test_get_config_file_contents_with_single_run_no_theme() {
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();

Expand Down Expand Up @@ -345,7 +345,7 @@ public function test_get_config_file_contents_with_parallel_run() {
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();

Expand Down Expand Up @@ -489,7 +489,7 @@ public function clean_features_path_list() {
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();
Expand Down Expand Up @@ -553,7 +553,7 @@ public function test_get_config_file_contents_with_blacklisted_tags() {
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();
Expand Down Expand Up @@ -632,7 +632,7 @@ public function test_get_config_file_contents_with_blacklisted_features_contexts
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();

Expand Down
72 changes: 36 additions & 36 deletions admin/tool/dataprivacy/tests/expired_contexts_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ public function test_process_user_context_with_override_unexpired_role() {
$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',
Expand All @@ -868,7 +868,7 @@ public function test_process_user_context_with_override_unexpired_role() {
$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);
Expand Down Expand Up @@ -935,7 +935,7 @@ public function test_process_course_context_with_override_unexpired_role() {
$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',
Expand All @@ -956,7 +956,7 @@ public function test_process_course_context_with_override_unexpired_role() {
}));

$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);
Expand Down Expand Up @@ -1023,7 +1023,7 @@ public function test_process_course_context_with_override_expired_role() {
$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',
Expand All @@ -1044,7 +1044,7 @@ public function test_process_course_context_with_override_expired_role() {
}));

$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);
Expand Down Expand Up @@ -1112,7 +1112,7 @@ public function test_process_course_context_with_user_in_both_lists() {
$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',
Expand All @@ -1133,7 +1133,7 @@ public function test_process_course_context_with_user_in_both_lists() {
}));

$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);
Expand Down Expand Up @@ -1208,7 +1208,7 @@ public function test_process_course_context_with_user_in_both_lists_expired() {
$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',
Expand All @@ -1229,7 +1229,7 @@ public function test_process_course_context_with_user_in_both_lists_expired() {
}));

$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);
Expand Down Expand Up @@ -1260,7 +1260,7 @@ public function test_process_not_setup() {
$expiredcontext->save();

$mockprivacymanager = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods([
->onlyMethods([
'delete_data_for_user',
'delete_data_for_all_users_in_context',
])
Expand All @@ -1269,7 +1269,7 @@ public function test_process_not_setup() {
$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());

Expand Down Expand Up @@ -1299,7 +1299,7 @@ public function test_process_none_approved() {
$expiredcontext->save();

$mockprivacymanager = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods([
->onlyMethods([
'delete_data_for_user',
'delete_data_for_all_users_in_context',
])
Expand All @@ -1308,7 +1308,7 @@ public function test_process_none_approved() {
$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());

Expand All @@ -1335,7 +1335,7 @@ public function test_process_no_context() {
$expiredcontext->save();

$mockprivacymanager = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods([
->onlyMethods([
'delete_data_for_user',
'delete_data_for_all_users_in_context',
])
Expand All @@ -1344,7 +1344,7 @@ public function test_process_no_context() {
$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());

Expand Down Expand Up @@ -1382,7 +1382,7 @@ public function test_process_user_context() {
$expiredcontext->save();

$mockprivacymanager = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods([
->onlyMethods([
'delete_data_for_user',
'delete_data_for_all_users_in_context',
])
Expand All @@ -1396,7 +1396,7 @@ public function test_process_user_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());

Expand Down Expand Up @@ -1442,7 +1442,7 @@ public function test_process_course_context() {
$expiredcontext->save();

$mockprivacymanager = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods([
->onlyMethods([
'delete_data_for_user',
'delete_data_for_all_users_in_context',
])
Expand All @@ -1451,7 +1451,7 @@ public function test_process_course_context() {
$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());

Expand Down Expand Up @@ -1494,7 +1494,7 @@ public function test_process_user_context_logged_in_after_approval() {
$this->setUser();

$mockprivacymanager = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods([
->onlyMethods([
'delete_data_for_user',
'delete_data_for_all_users_in_context',
])
Expand All @@ -1503,7 +1503,7 @@ public function test_process_user_context_logged_in_after_approval() {
$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());

Expand Down Expand Up @@ -1546,7 +1546,7 @@ public function test_process_user_context_changed_after_approved() {
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',
])
Expand All @@ -1555,7 +1555,7 @@ public function test_process_user_context_changed_after_approved() {
$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());

Expand Down Expand Up @@ -1600,7 +1600,7 @@ public function test_process_user_historic_block_unapproved() {
$expiredblockcontext->save();

$mockprivacymanager = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods([
->onlyMethods([
'delete_data_for_user',
'delete_data_for_all_users_in_context',
])
Expand All @@ -1614,7 +1614,7 @@ public function test_process_user_historic_block_unapproved() {
);

$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());

Expand Down Expand Up @@ -1653,7 +1653,7 @@ public function test_process_user_historic_unexpired_child() {
$expiredusercontext->save();

$mockprivacymanager = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods([
->onlyMethods([
'delete_data_for_user',
'delete_data_for_all_users_in_context',
])
Expand All @@ -1667,7 +1667,7 @@ public function test_process_user_historic_unexpired_child() {
);

$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());

Expand Down Expand Up @@ -1705,7 +1705,7 @@ public function test_process_course_context_updated() {
$expiredcontext->save();

$mockprivacymanager = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods([
->onlyMethods([
'delete_data_for_user',
'delete_data_for_all_users_in_context',
])
Expand All @@ -1714,7 +1714,7 @@ public function test_process_course_context_updated() {
$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);
Expand Down Expand Up @@ -1756,7 +1756,7 @@ public function test_process_course_context_outstanding_children() {
$expiredcontext->save();

$mockprivacymanager = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods([
->onlyMethods([
'delete_data_for_user',
'delete_data_for_all_users_in_context',
])
Expand All @@ -1765,7 +1765,7 @@ public function test_process_course_context_outstanding_children() {
$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());

Expand Down Expand Up @@ -1814,7 +1814,7 @@ public function test_process_course_context_pending_children() {
$expiredforumcontext->save();

$mockprivacymanager = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods([
->onlyMethods([
'delete_data_for_user',
'delete_data_for_all_users_in_context',
])
Expand All @@ -1823,7 +1823,7 @@ public function test_process_course_context_pending_children() {
$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());

Expand Down Expand Up @@ -1872,7 +1872,7 @@ public function test_process_course_context_approved_children() {
$expiredforumcontext->save();

$mockprivacymanager = $this->getMockBuilder(\core_privacy\manager::class)
->setMethods([
->onlyMethods([
'delete_data_for_user',
'delete_data_for_all_users_in_context',
])
Expand All @@ -1886,7 +1886,7 @@ public function test_process_course_context_approved_children() {
);

$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());

Expand Down
2 changes: 1 addition & 1 deletion admin/tool/dataprivacy/tests/filtered_userlist_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 81407f1

Please sign in to comment.