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..63cc2a40b6 100644 --- a/tests/unit/Codeception/Subscriber/ErrorHandlerTest.php +++ b/tests/unit/Codeception/Subscriber/ErrorHandlerTest.php @@ -5,8 +5,20 @@ use Codeception\Subscriber\ErrorHandler; use Codeception\Suite; -class ErrorHandlerTest extends \PHPUnit\Framework\TestCase +class ErrorHandlerTest extends \Codeception\PHPUnit\TestCase { + private $originalErrorLevel; + + public function _setUp() + { + $this->originalErrorLevel = error_reporting(); + } + + public function _tearDown() + { + // Deprecation message test changes error_level + error_reporting($this->originalErrorLevel); + } public function testDeprecationMessagesRespectErrorLevelSetting() { @@ -23,4 +35,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->expectExceptionMessage("Undefined variable: a at tests{$SEP}unit{$SEP}Codeception{$SEP}Subscriber{$SEP}ErrorHandlerTest.php:45"); + $b = $a + 1; + } }