From a0741daf7b6b93c83ab3933db393d628dbe25674 Mon Sep 17 00:00:00 2001 From: Mystael Date: Fri, 28 Aug 2020 09:13:16 +0200 Subject: [PATCH] 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 --- AssertThrows.php | 8 ++++---- tests/AssertThrowsTest.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/AssertThrows.php b/AssertThrows.php index 25e3ac0..e237ced 100644 --- a/AssertThrows.php +++ b/AssertThrows.php @@ -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; @@ -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"); } } diff --git a/tests/AssertThrowsTest.php b/tests/AssertThrowsTest.php index dcd05b0..8c78d78 100644 --- a/tests/AssertThrowsTest.php +++ b/tests/AssertThrowsTest.php @@ -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 :(");