diff --git a/src/Util.php b/src/Util.php index ead8e82..db3634e 100644 --- a/src/Util.php +++ b/src/Util.php @@ -126,7 +126,7 @@ public static function ensureNot($valueToThrowOn, $valueToCheck, $exception = nu */ private static function buildException($exception, array $exceptionArgs = null) : Throwable { - if ($exception instanceof Exception) { + if ($exception instanceof Throwable) { return $exception; } diff --git a/tests/UtilTest.php b/tests/UtilTest.php index 3ff46d4..a893bc2 100644 --- a/tests/UtilTest.php +++ b/tests/UtilTest.php @@ -2,12 +2,14 @@ namespace TraderInteractive; +use Error; use Throwable; use TraderInteractive\Util as Utility; use ErrorException; use Exception; use InvalidArgumentException; use PHPUnit\Framework\TestCase; +use TypeError; /** * @coversDefaultClass \TraderInteractive\Util @@ -256,6 +258,16 @@ public function ensureSuccess() $this->assertTrue(Utility::ensure(true, is_string('boo'))); } + /** + * @test + * @covers ::ensure + */ + public function ensureSuccessWithErrorObject() + { + $error = new Error('the error'); + $this->assertTrue(Util::ensure(true, is_string('foo'), $error)); + } + /** * @test * @covers ::ensure @@ -322,6 +334,18 @@ public function ensureException() Utility::ensure(true, false, new Exception('foo', 2)); } + /** + * @test + * @covers ::ensure + */ + public function ensureThrowsErrorObject() + { + $error = new TypeError('the error'); + $this->expectException(TypeError::class); + $this->expectExceptionMessage($error->getMessage()); + Utility::ensure(true, false, $error); + } + /** * @test * @covers ::setExceptionAliases