PHP Unit Testing: How can we pass multiple parameters while mocking a method? -


    $observer = $this->getmockbuilder('apps_sample_datahandler')             ->disableoriginalconstructor()             ->disableoriginalclone()             ->disableargumentcloning()             ->getmock();      $observer->method('getsampledata')          ->will($this->returncallback('mocktestcall'));       $this->assertequals('foo', $observer->getsampledata()); 

here trying mock method 'getsampledata' 'mocktestcall'.

we wanted know how can pass parameter method 'mocktestcall'.

definition method 'mocktestcall' given below:

public function mocktestcall($arg1){     return $arg1; } 

for php >= 5.4:

$observer->method('getsampledata')     ->will($this->returncallback(         function() {             $this->mocktestcall('arg1_value');         }     )); 

for php 5.3:

$that = $this; $observer->method('getsampledata')     ->will($this->returncallback(         function() use($that) {             $that->mocktestcall('arg1_value');         }     )); 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -