Skip to content

Commit

Permalink
Show origin of warning in error message
Browse files Browse the repository at this point in the history
Fixes #6090
  • Loading branch information
Naktibalda committed Jan 23, 2021
1 parent 3579d06 commit 2dd425e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Codeception/Subscriber/ErrorHandler.php
Expand Up @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/Codeception/Subscriber/ErrorHandlerTest.php
Expand Up @@ -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;
}
}

0 comments on commit 2dd425e

Please sign in to comment.