Skip to content

Commit

Permalink
Start exception messages with capita letter
Browse files Browse the repository at this point in the history
* Add an exception message in case different exception was thrown.

* Format messages

* update test

Co-authored-by: Marek Kolcun <[email protected]>
  • Loading branch information
Mystael and Marek Kolcun authored Aug 28, 2020
1 parent 20517b8 commit a0741da
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions AssertThrows.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ public function assertThrowsWithMessage($throws, $message, callable $fn)
}

if ($message !== false && $message !== strtolower($e->getMessage())) {
throw new AssertionFailedError("exception message '$message' was expected, but '" . $e->getMessage() . "' was received");
throw new AssertionFailedError("Exception message '$message' was expected, but '" . $e->getMessage() . "' was received");
}

} catch (\Exception $e) {
if ($throws) {
if ($throws !== get_class($e)) {
throw new AssertionFailedError("exception '$throws' was expected, but " . get_class($e) . ' was thrown');
throw new AssertionFailedError("Exception '$throws' was expected, but " . get_class($e) . " was thrown with message '" . $e->getMessage() . "'");
}

if ($message !== false && $message !== strtolower($e->getMessage())) {
throw new AssertionFailedError("exception message '$message' was expected, but '" . $e->getMessage() . "' was received");
throw new AssertionFailedError("Exception message '$message' was expected, but '" . $e->getMessage() . "' was received");
}
} else {
throw $e;
Expand All @@ -71,7 +71,7 @@ public function assertThrowsWithMessage($throws, $message, callable $fn)
if (isset($e)) {
$this->assertTrue(true, 'exception handled');
} else {
throw new AssertionFailedError("exception '$throws' was not thrown as expected");
throw new AssertionFailedError("Exception '$throws' was not thrown as expected");
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/AssertThrowsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function testExceptionMessageFails()
throw new MyException("hallo");
});
} catch (AssertionFailedError $e) {
$this->assertEquals("exception message 'hello' was expected, but 'hallo' was received", $e->getMessage());
$this->assertEquals("Exception message 'hello' was expected, but 'hallo' was received", $e->getMessage());
return;
}
$this->fail("Ups :(");
Expand Down

0 comments on commit a0741da

Please sign in to comment.