From 2dd425eee375a136bd817d08033d5bbd43b3e1e1 Mon Sep 17 00:00:00 2001 From: Gintautas Miselis Date: Sat, 23 Jan 2021 20:51:48 +0200 Subject: [PATCH] Show origin of warning in error message Fixes #6090 --- src/Codeception/Subscriber/ErrorHandler.php | 3 ++- tests/unit/Codeception/Subscriber/ErrorHandlerTest.php | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Codeception/Subscriber/ErrorHandler.php b/src/Codeception/Subscriber/ErrorHandler.php index e12fdee188..735f8c87c0 100644 --- a/src/Codeception/Subscriber/ErrorHandler.php +++ b/src/Codeception/Subscriber/ErrorHandler.php @@ -80,7 +80,8 @@ public function errorHandler($errno, $errstr, $errfile, $errline, $context = arr return false; } - throw new \PHPUnit\Framework\Exception($errstr, $errno); + $relativePath = codecept_relative_path($errfile); + throw new \PHPUnit\Framework\Exception("$errstr at $relativePath:$errline", $errno); } public function shutdownHandler() diff --git a/tests/unit/Codeception/Subscriber/ErrorHandlerTest.php b/tests/unit/Codeception/Subscriber/ErrorHandlerTest.php index 2acc879fb3..c707ec9ef9 100644 --- a/tests/unit/Codeception/Subscriber/ErrorHandlerTest.php +++ b/tests/unit/Codeception/Subscriber/ErrorHandlerTest.php @@ -23,4 +23,12 @@ public function testDeprecationMessagesRespectErrorLevelSetting() $this->assertEquals([], Notification::all(), 'Deprecation message was added to notifications'); } + + public function testShowsLocationOfWarning() + { + $this->expectException(\PHPUnit\Framework\Exception::class); + $SEP = DIRECTORY_SEPARATOR; + $this->expectErrorMessage("Undefined variable: a at tests{$SEP}unit{$SEP}Codeception{$SEP}Subscriber{$SEP}ErrorHandlerTest.php:32"); + $b = $a + 1; + } }