Skip to content

Commit

Permalink
fix error with phpunit10 (undefined method setMethods())
Browse files Browse the repository at this point in the history
 Was removed in phpunit10

 Error: Call to undefined method PHPUnit\Framework\MockObject\MockBuilder::setMethods()
  • Loading branch information
tenzap committed Jun 19, 2023
1 parent 43621f2 commit 0c52aa9
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions tests/codeigniter/core/Loader_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public function test_load_view()
$this->assertEquals($content.'undefined', $out);

// Mock output class
$output = $this->getMockBuilder('CI_Output')->setMethods(array('append_output'))->getMock();
$output = $this->getMockBuilder('CI_Output')->onlyMethods(array('append_output'))->getMock();
$output->expects($this->once())->method('append_output')->with($content.$value);
$this->ci_instance_var('output', $output);

Expand Down Expand Up @@ -483,7 +483,7 @@ public function test_language()
{
// Mock lang class and test load call
$file = 'test';
$lang = $this->getMockBuilder('CI_Lang')->setMethods(array('load'))->getMock();
$lang = $this->getMockBuilder('CI_Lang')->onlyMethods(array('load'))->getMock();
$lang->expects($this->once())->method('load')->with($file);
$this->ci_instance_var('lang', $lang);
$this->assertInstanceOf('CI_Loader', $this->load->language($file));
Expand Down
2 changes: 1 addition & 1 deletion tests/codeigniter/helpers/language_helper_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Language_helper_test extends CI_TestCase {
public function test_lang()
{
$this->helper('language');
$lang = $this->getMockBuilder('CI_Lang')->setMethods(array('line'))->getMock();
$lang = $this->getMockBuilder('CI_Lang')->onlyMethods(array('line'))->getMock();
$lang->expects($this->any())->method('line')->will($this->returnValue(FALSE));
$this->ci_instance_var('lang', $lang);

Expand Down
2 changes: 1 addition & 1 deletion tests/codeigniter/helpers/number_helper_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function set_up()

// Mock away load, too much going on in there,
// we'll just check for the expected parameter
$lang = $this->getMockBuilder('CI_Lang')->setMethods(array('load'))->getMock();
$lang = $this->getMockBuilder('CI_Lang')->onlyMethods(array('load'))->getMock();
$lang->expects($this->once())
->method('load')
->with($this->equalTo('number'));
Expand Down
4 changes: 2 additions & 2 deletions tests/codeigniter/libraries/Calendar_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ class Calendar_test extends CI_TestCase {
public function set_up()
{
// Required for get_total_days()
$this->ci_instance_var('load', $this->getMockBuilder('CI_Loader')->setMethods(array('helper'))->getMock());
$this->ci_instance_var('load', $this->getMockBuilder('CI_Loader')->onlyMethods(array('helper'))->getMock());

$lang = $this->getMockBuilder('CI_Lang')->setMethods(array('load', 'line'))->getMock();
$lang = $this->getMockBuilder('CI_Lang')->onlyMethods(array('load', 'line'))->getMock();
$lang->expects($this->any())->method('line')->will($this->returnValue(FALSE));
$this->ci_instance_var('lang', $lang);

Expand Down
2 changes: 1 addition & 1 deletion tests/codeigniter/libraries/Driver_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function set_up()

// Mock Loader->get_package_paths
$paths = 'get_package_paths';
$ldr = $this->getMockBuilder('CI_Loader')->setMethods(array($paths))->getMock();
$ldr = $this->getMockBuilder('CI_Loader')->onlyMethods(array($paths))->getMock();
$ldr->expects($this->any())->method($paths)->will($this->returnValue(array(APPPATH, BASEPATH)));
$this->ci_instance_var('load', $ldr);

Expand Down
4 changes: 2 additions & 2 deletions tests/codeigniter/libraries/Form_validation_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ public function set_up()

// Create a mock loader since load->helper() looks in the wrong directories for unit tests,
// We'll use CI_TestCase->helper() instead
$loader = $this->getMockBuilder('CI_Loader')->setMethods(array('helper'))->getMock();
$loader = $this->getMockBuilder('CI_Loader')->onlyMethods(array('helper'))->getMock();

// Same applies for lang
$lang = $this->getMockBuilder('CI_Lang')->setMethods(array('load'))->getMock();
$lang = $this->getMockBuilder('CI_Lang')->onlyMethods(array('load'))->getMock();

$security = new Mock_Core_Security('UTF-8');
$input = new CI_Input($security);
Expand Down
2 changes: 1 addition & 1 deletion tests/codeigniter/libraries/Upload_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public function set_up()
$ci = $this->ci_instance();
$ci->upload = new CI_Upload();
$ci->security = new Mock_Core_Security('UTF-8');
$ci->lang = $this->getMockBuilder('CI_Lang')->setMethods(array('load', 'line'))->getMock();
$ci->lang = $this->getMockBuilder('CI_Lang')->onlyMethods(array('load', 'line'))->getMock();
$ci->lang->expects($this->any())->method('line')->will($this->returnValue(FALSE));
$this->upload = $ci->upload;
}
Expand Down

0 comments on commit 0c52aa9

Please sign in to comment.