Skip to content

Commit a0741da

Browse files
MystaelMarek Kolcun
andauthored
Start exception messages with capita letter
* Add an exception message in case different exception was thrown. * Format messages * update test Co-authored-by: Marek Kolcun <[email protected]>
1 parent 20517b8 commit a0741da

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

AssertThrows.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ public function assertThrowsWithMessage($throws, $message, callable $fn)
5050
}
5151

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

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

6262
if ($message !== false && $message !== strtolower($e->getMessage())) {
63-
throw new AssertionFailedError("exception message '$message' was expected, but '" . $e->getMessage() . "' was received");
63+
throw new AssertionFailedError("Exception message '$message' was expected, but '" . $e->getMessage() . "' was received");
6464
}
6565
} else {
6666
throw $e;
@@ -71,7 +71,7 @@ public function assertThrowsWithMessage($throws, $message, callable $fn)
7171
if (isset($e)) {
7272
$this->assertTrue(true, 'exception handled');
7373
} else {
74-
throw new AssertionFailedError("exception '$throws' was not thrown as expected");
74+
throw new AssertionFailedError("Exception '$throws' was not thrown as expected");
7575
}
7676
}
7777

tests/AssertThrowsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testExceptionMessageFails()
3232
throw new MyException("hallo");
3333
});
3434
} catch (AssertionFailedError $e) {
35-
$this->assertEquals("exception message 'hello' was expected, but 'hallo' was received", $e->getMessage());
35+
$this->assertEquals("Exception message 'hello' was expected, but 'hallo' was received", $e->getMessage());
3636
return;
3737
}
3838
$this->fail("Ups :(");

0 commit comments

Comments
 (0)