Skip to content

Commit

Permalink
Assert::exception() prints stack of unexpected exception
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Apr 27, 2022
1 parent 2e788e2 commit 86f49e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/Framework/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,10 @@ public static function exception(
self::fail("$class was expected but got " . get_class($e) . ($e->getMessage() ? " ({$e->getMessage()})" : ''), null, null, $e);

} elseif ($message && !self::isMatching($message, $e->getMessage())) {
self::fail("$class with a message matching %2 was expected but got %1", $e->getMessage(), $message);
self::fail("$class with a message matching %2 was expected but got %1", $e->getMessage(), $message, $e);

} elseif ($code !== null && $e->getCode() !== $code) {
self::fail("$class with a code %2 was expected but got %1", $e->getCode(), $code);
self::fail("$class with a code %2 was expected but got %1", $e->getCode(), $code, $e);
}

return $e;
Expand Down
16 changes: 8 additions & 8 deletions tests/Framework/Assert.exception.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ $e = Assert::exception(function () use (&$inner) {
}, Tester\AssertException::class, 'UnknownException was expected but got Exception (message)');
Assert::same($inner, $e->getPrevious());

$e = Assert::exception(function () {
Assert::exception(function () {
throw new Exception('Text');
$e = Assert::exception(function () use (&$inner) {
Assert::exception(function () use (&$inner) {
throw $inner = new Exception('Text');
}, Exception::class, 'Abc');
}, Tester\AssertException::class, "Exception with a message matching 'Abc' was expected but got 'Text'");
Assert::null($e->getPrevious());
Assert::same($inner, $e->getPrevious());

Assert::exception(function () {
throw new Exception('Text', 42);
}, Exception::class, null, 42);

$e = Assert::exception(function () {
Assert::exception(function () {
throw new Exception('Text', 1);
$e = Assert::exception(function () use (&$inner) {
Assert::exception(function () use (&$inner) {
throw $inner = new Exception('Text', 1);
}, Exception::class, null, 42);
}, Tester\AssertException::class, 'Exception with a code 42 was expected but got 1');
Assert::null($e->getPrevious());
Assert::same($inner, $e->getPrevious());

$old = Assert::$onFailure;
Assert::$onFailure = function () {};
Expand Down

0 comments on commit 86f49e2

Please sign in to comment.