I have a class that handles errors, including exceptions. If an exception is caught, I will pass the exception as an argument to my exception / error handler.
try {
someTrowingFnc();
} catch (\Exception $e) {
this->error->exception($e);
}
Now I want a unit test handler for this error and make fun of the exception.
It's hard for me to mock this exception so that I can manage the message, file, and exception line.
$exceptionMock = $this->getMock('Exception', array(
'getFile',
'getLine',
'getMessage',
'getTrace'
));
$exceptionMock->expects($this->any())
->method('getFile')
->willReturn('/file/name');
$exceptionMock->expects($this->any())
->method('getLine')
->willReturn('3069');
$exceptionMock->expects($this->any())
->method('getMessage')
->willReturn('Error test');
The results below always return NULL.
$file = $exception->getFile();
$line = $exception->getLine();
$msg = $exception->getMessage();
Is there a way around the exceptions, or am I just doing something wrong?
source
share