Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
24 changes: 24 additions & 0 deletions tests/UtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down