leo icon indicating copy to clipboard operation
leo copied to clipboard

Feature request: Allow asserting that trigger_error() is called

Open mallorydxw opened this issue 8 years ago • 1 comments

PHPUnit has $this->setExpectedException('PHPUnit_Framework_Error_Warning');. Leo should provide some way of doing this too. Something like this:

expect(function () {
    trigger_error('Oh no!', E_USER_WARNING);
})->to->triggererror(E_USER_WARNING, 'Oh no!');

mallorydxw avatar Aug 08 '16 19:08 mallorydxw

Sounds like a good idea to me! For now, I'll shamelessly plug a couple of my own libraries that might help you out:

  • errors/exceptions will automatically install an error handler that turns errors into error exceptions.
  • Asplode is very similar, but requires you to call Asplode::install() in your peridot.php.

Neither of these handlers throw different error exception types for different error severities. If you need that level of granularity, you'll have to use a try/catch block for now.

Also please be aware of #20. It will probably affect you also, if you choose one of the above approaches.

ezzatron avatar Aug 08 '16 23:08 ezzatron