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

@ -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