Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show origin of warning in error message #6094

Merged
merged 1 commit into from Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
TavoNiievez marked this conversation as resolved.
Show resolved Hide resolved
}

public function shutdownHandler()
Expand Down
26 changes: 25 additions & 1 deletion tests/unit/Codeception/Subscriber/ErrorHandlerTest.php
Expand Up @@ -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()
{
Expand All @@ -23,4 +35,16 @@ public function testDeprecationMessagesRespectErrorLevelSetting()

$this->assertEquals([], Notification::all(), 'Deprecation message was added to notifications');
}

public function testShowsLocationOfWarning()
{
if (PHP_MAJOR_VERSION === 5) {
$this->expectException(\PHPUnit_Framework_Exception::class);
} else {
$this->expectException(\PHPUnit\Framework\Exception::class);
}
$SEP = DIRECTORY_SEPARATOR;
$this->expectExceptionMessage("Undefined variable: file at tests{$SEP}unit{$SEP}Codeception{$SEP}Subscriber{$SEP}ErrorHandlerTest.php:48");
trigger_error('Undefined variable: file', E_USER_WARNING);
}
}