mocking - PHPUnit: Pass mock object as method parameter -


say have following class:

class document {   private file;    public function setfile(uploadedfile $file)   {     $this->file = $file;   }    public function getext()   {     return $this->file->guessextension();   } } 

i'd test getext() method. tried set test follows:

$file = $this->getmock('uploadedfile');  $file->expects($this->at(0))   ->method('guessextension')   ->will($this->returnvalue('png'));  $doc = new document(); $doc->setfile($file); ... 

however, giving me error saying setfile() expecting instance of uploadedfile , mock object found instead. can shed light on how test kind of scenario? beginner when comes testing mocks , stubs.

thanks!

thanks fab's comment. made following change , got working,

$file = $this->getmockbuilder('symfony\component\httpfoundation\file\uploadedfile')         ->disableoriginalconstructor()         ->getmock(); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -