Add FramesIterator & tests

This commit is contained in:
filp
2013-03-12 10:54:14 +00:00
parent 410b42fa91
commit d2dfdbb108
3 changed files with 38 additions and 7 deletions
+13
View File
@@ -0,0 +1,13 @@
<?php
/**
* Damnit - php errors for cool kids
* @author Filipe Dobreira <http://github.com/filp>
*/
namespace Damnit\Exception;
use \ArrayIterator;
/**
* @todo might be removed soon-ish
*/
class FrameIterator extends ArrayIterator {}
+12 -5
View File
@@ -5,13 +5,9 @@
*/
namespace Damnit\Exception;
use Damnit\Exception\FrameIterator;
use \Exception;
/**
* The Inspector is able to lazily inspect an
* exception, and gather information about its
* related components.
*/
class Inspector
{
/**
@@ -34,4 +30,15 @@ class Inspector
{
return $this->exception;
}
/**
* Returns an iterator for the inspected exception's
* frames.
* @return DamnIt\Exception\FrameIterator
*/
public function getFrames()
{
$iterator = new FrameIterator($this->exception->getTrace());
return $iterator;
}
}
+13 -2
View File
@@ -22,8 +22,8 @@ class InspectorTest extends TestCase
}
/**
* @covers DamnIt\Exception\Inspector::__construct
* @covers DamnIt\Exception\Inspector::getException
* @covers Damnit\Exception\Inspector::__construct
* @covers Damnit\Exception\Inspector::getException
*/
public function testExceptionIsStoredAndReturned()
{
@@ -32,4 +32,15 @@ class InspectorTest extends TestCase
$this->assertSame($exception, $inspector->getException());
}
/**
* @covers Damnit\Exception\Inspector::getFrames
*/
public function testGetFramesReturnsIterator()
{
$exception = new RuntimeException;
$inspector = $this->getInspectorInstance($exception);
$this->assertInstanceOf('Damnit\\Exception\\FrameIterator', $inspector->getFrames());
}
}