php-mock/php-mock-phpunit

Multiple returns

vincentchalamon opened this issue · 1 comments

Hi,
I'm trying to create a mock of file_get_contents function. On the first call, it should throw an exception, but on the second call it should return a value. How can I mock it?:

try {
    $content = 'data:image/jpeg;base64,'.base64_encode(file_get_contents($url));
} catch (\Exception $e) {
    $content = 'data:image/jpeg;base64,'.base64_encode(file_get_contents(realpath(__DIR__.'/path/to/my/image.png')));
}

That's a PHPUnit question. I'll close it therefore. Please consult the PHPUnit documentation for this question.