try / predict-exception
如果一段代码抛出异常时的简化预测
1.1.0
2018-02-08 21:47 UTC
This package is not auto-updated.
Last update: 2024-09-24 03:44:06 UTC
README
如果一段代码抛出异常时的简化预测
安装
$ composer require try/predict-exception
用法
<?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
方法
predictException($capture, $exceptionClass)
检查给定代码块是否抛出预期类型的 Throwable 的方法。
参数
许可
GPL-2.0 © Willi Eßer