error-code should be wrapped in ErrorException->severity. fixes #267.

This commit is contained in:
Markus Staab
2015-03-13 09:51:41 +01:00
parent dcce91553e
commit 6a82df42df
3 changed files with 24 additions and 2 deletions
+2 -1
View File
@@ -130,7 +130,8 @@ class PrettyPageHandler extends Handler
$code = $inspector->getException()->getCode();
if ($inspector->getException() instanceof \ErrorException) {
$code = Misc::translateErrorCode($code);
// ErrorExceptions wrap the php-error types within the "severity" property
$code = Misc::translateErrorCode($inspector->getException()->getSeverity());
}
// List of variables that will be passed to the layout template.
+3 -1
View File
@@ -317,7 +317,9 @@ class Run
}
}
$exception = new ErrorException($message, $level, 0, $file, $line);
// XXX we pass $level for the "code" param only for BC reasons.
// see https://github.com/filp/whoops/issues/267
$exception = new ErrorException($message, /*code*/ $level, /*severity*/ $level, $file, $line);
if ($this->canThrowExceptions) {
throw $exception;
} else {
+19
View File
@@ -364,6 +364,25 @@ class RunTest extends TestCase
$this->assertTrue($error && strpos($error['message'], 'strpos()') !== false);
}
/**
* @covers Whoops\Run::handleError
* @see https://github.com/filp/whoops/issues/267
*/
public function testErrorWrappedInException()
{
try {
$run = $this->getRunInstance();
$run->handleError(E_WARNING, 'my message', 'my file', 99);
$this->fail("missing expected exception");
} catch (\ErrorException $e) {
$this->assertSame(E_WARNING, $e->getSeverity());
$this->assertSame(E_WARNING, $e->getCode(), "For BC reasons getCode() should match getSeverity()");
$this->assertSame('my message', $e->getMessage());
$this->assertSame('my file', $e->getFile());
$this->assertSame(99, $e->getLine());
}
}
/**
* @covers Whoops\Run::handleException
* @covers Whoops\Run::writeToOutput