From 43bc40a96578d1b14fe6477b4cf615b77505f9c2 Mon Sep 17 00:00:00 2001 From: Diego Vieira Date: Wed, 17 Jan 2018 14:44:59 +0000 Subject: [PATCH] Allow message to be case insensitive --- AssertThrows.php | 4 +++- tests/AssertThrowsTest.php | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/AssertThrows.php b/AssertThrows.php index ea406a2..75f7664 100644 --- a/AssertThrows.php +++ b/AssertThrows.php @@ -33,10 +33,12 @@ public function assertThrowsWithMessage($throws, $message, callable $fn) $result = $this->getTestResultObject(); if (is_array($throws)) { - $message = ($throws[1]) ? strtolower($throws[1]) : false; + $message = ($throws[1]) ? $throws[1] : false; $throws = $throws[0]; } + $message = strtolower($message); + try { call_user_func($fn); } catch (AssertionFailedError $e) { diff --git a/tests/AssertThrowsTest.php b/tests/AssertThrowsTest.php index 996ca5f..bd31879 100644 --- a/tests/AssertThrowsTest.php +++ b/tests/AssertThrowsTest.php @@ -35,6 +35,13 @@ public function testExceptionMessageFails() $this->fail("Ups :("); } + public function testExceptionMessageCaseInsensitive() + { + $this->assertThrowsWithMessage(MyException::class, "Message and Expected Message CAN have different case", function() { + throw new MyException("Message and expected message can have different case"); + }); + } + } class MyException extends Exception {