Say I have the following class:
class Document
{
private file;
public function setFile(UploadedFile $file)
{
$this->file = $file;
}
public function getExt()
{
return $this->file->guessExtension();
}
}
I'd like to test the getExt() method. I tried to set up the test as follows:
$file = $this->getMock('UploadedFile');
$file->expects($this->at(0))
->method('guessExtension')
->will($this->returnValue('png'));
$doc = new Document();
$doc->setFile($file);
...
However, it is giving me error saying that setFile() is expecting an instance of UploadedFile and the mock object is found instead. Can anyone shed some light on how to test this kind of scenario? I am a beginner when it comes to testing with mocks and stubs.
Thanks!