I am stumbling a bit with finding a way to test that my exception handler is being called upon thrown Exception.
This is the idea that I initially working with for the testing:
class ClientSpec extends ObjectBehavior
{
function it_should_catch_exceptions(Config $config)
{
$e = new Exception('test exception');
$this->catchException($e)->shouldBeCalled();
throw $e;
}
}
The Client
has a method catchException
which will be set as exception handler through set_exception_handler
: http://php.net/set_exception_handler.
Running this test gives me this feedback: no beCalled([array:0]) matcher found for null
, so I've also tried to do create a spec for Exception
and do the following:
class ExceptionSpec extends ObjectBehavior
{
function it_should_trigger_opbeat_client_when_thrown(Client $client)
{
$client->catchException($this)->shouldBeCalled();
throw $this->getWrappedObject();
}
}
But running this test returns another error: exception [exc:Exception("")] has been thrown
How can I test that my exception handler is called?