try / predict-exception
Simplified predictions if a piece of codes throws an Exception
1.1.0
2018-02-08 21:47 UTC
This package is not auto-updated.
Last update: 2024-12-31 05:04:03 UTC
README
Simplified predictions if a piece of codes throws an Exception
Install
$ composer require try/predict-exception
Usage
<?php require_once '/path/to/autoload.php'; use TryPhp\PredictExeptionTrait; $assertions = new class() { use PredictExeptionTrait(); } $assertions->predictException(function () { throw new \RuntimeException('Oooops. Something broke.') }, \RuntimeException::class); // won't throw an exception $assertions->predictException(function () { }, \Exception::class); // will throw an exception $assertions->predictException(function () { throw new \RuntimeException('something else happened.'); }, \Exception::class); // will throw an exception
API
Methods
predictException($capture, $exceptionClass)
Method to check if a given piece of code throws an Throwable of the expected type.
Arguments
License
GPL-2.0 © Willi Eßer