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 -

Laravel mail error `Swift_TransportException in StreamBuffer.php line 269: Connection could not be established with host smtp.gmail.com [ #0]` -

c# SetCompatibleTextRenderingDefault must be called before the first -