mirror of
https://github.com/filp/whoops.git
synced 2026-09-10 09:46:18 +00:00
Add initial support for chained exception inspection
This commit is contained in:
@@ -21,6 +21,11 @@ class Inspector
|
||||
*/
|
||||
private $frames;
|
||||
|
||||
/**
|
||||
* @var Whoops\Exception\Inspector
|
||||
*/
|
||||
private $previousExceptionInspector;
|
||||
|
||||
/**
|
||||
* @param Exception $exception The exception to inspect
|
||||
*/
|
||||
@@ -53,6 +58,33 @@ class Inspector
|
||||
return $this->exception->getMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this Exception have a previous Exception?
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPreviousException()
|
||||
{
|
||||
return !!$this->previousExceptionInspector || !!$this->exception->getPrevious();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an inspector for a previous inspector, if any.
|
||||
* @todo Clean this up a bit, cache stuff a bit better.
|
||||
* @return Whoops\Exception\Inspector|null
|
||||
*/
|
||||
public function getPreviousExceptionInspector()
|
||||
{
|
||||
if($this->previousExceptionInspector === null) {
|
||||
$previousException = $this->exception->getPrevious();
|
||||
|
||||
if($previousException) {
|
||||
$this->previousExceptionInspector = new Inspector($previousException);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->previousExceptionInspector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator for the inspected exception's
|
||||
* frames.
|
||||
|
||||
@@ -7,19 +7,19 @@
|
||||
namespace Whoops\Exception;
|
||||
use Whoops\Exception\Inspector;
|
||||
use Whoops\TestCase;
|
||||
use RuntimeException;
|
||||
use Exception;
|
||||
use Mockery as m;
|
||||
|
||||
class InspectorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @param string $message
|
||||
* @param string $message
|
||||
* @param int $code
|
||||
* @param Exception $previous
|
||||
* @return Exception
|
||||
*/
|
||||
protected function getException($message = null)
|
||||
protected function getException($message = null, $code = 0, Exception $previous = null)
|
||||
{
|
||||
return m::mock('Exception', array($message));
|
||||
return new Exception($message, $code, $previous);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,4 +64,29 @@ class InspectorTest extends TestCase
|
||||
|
||||
$this->assertInstanceOf('Whoops\\Exception\\FrameCollection', $inspector->getFrames());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\Inspector::hasPreviousException
|
||||
* @covers Whoops\Exception\Inspector::getPreviousExceptionInspector
|
||||
*/
|
||||
public function testPreviousException()
|
||||
{
|
||||
$previousException = $this->getException("I'm here first!");
|
||||
$exception = $this->getException("Oh boy", null, $previousException);
|
||||
$inspector = $this->getInspectorInstance($exception);
|
||||
|
||||
$this->assertTrue($inspector->hasPreviousException());
|
||||
$this->assertEquals($previousException, $inspector->getPreviousExceptionInspector()->getException());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\Inspector::hasPreviousException
|
||||
*/
|
||||
public function testNegativeHasPreviousException()
|
||||
{
|
||||
$exception = $this->getException("Oh boy");
|
||||
$inspector = $this->getInspectorInstance($exception);
|
||||
|
||||
$this->assertFalse($inspector->hasPreviousException());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user