From 55bd123ebdbff70774d156f7c405eeb0432cbd3a Mon Sep 17 00:00:00 2001 From: Arthur Skobara Date: Mon, 19 Feb 2018 16:28:51 +0700 Subject: [PATCH] fix #4. assertThrow: do not raise an exception when messages are mismatched --- AssertThrows.php | 4 +++- tests/AssertThrowsTest.php | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/AssertThrows.php b/AssertThrows.php index 75f7664..25e3ac0 100644 --- a/AssertThrows.php +++ b/AssertThrows.php @@ -37,7 +37,9 @@ public function assertThrowsWithMessage($throws, $message, callable $fn) $throws = $throws[0]; } - $message = strtolower($message); + if (is_string($message)) { + $message = strtolower($message); + } try { call_user_func($fn); diff --git a/tests/AssertThrowsTest.php b/tests/AssertThrowsTest.php index bd31879..dcd05b0 100644 --- a/tests/AssertThrowsTest.php +++ b/tests/AssertThrowsTest.php @@ -11,8 +11,11 @@ public function testBasicException() $this->assertThrows(MyException::class, function() { throw new MyException(); }); + $this->assertThrows(MyException::class, function() { + throw new MyException('with ignored message'); + }); $this->assertTrue(true); - $this->assertEquals($count + 2, \PHPUnit\Framework\Assert::getCount()); + $this->assertEquals($count + 3, \PHPUnit\Framework\Assert::getCount()); } public function testExceptionWithMessage()