From fe1c72287a37f0e50f58865d46d685754f3da079 Mon Sep 17 00:00:00 2001 From: filp Date: Fri, 10 May 2013 19:02:25 +0100 Subject: [PATCH] Add FrameCollection tests --- src/Whoops/Exception/Frame.php | 16 ++--- .../Whoops/Exception/FrameCollectionTest.php | 71 +++++++++++++++++++ tests/Whoops/Exception/FrameTest.php | 1 + 3 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 tests/Whoops/Exception/FrameCollectionTest.php diff --git a/src/Whoops/Exception/Frame.php b/src/Whoops/Exception/Frame.php index a4a8d56..a97268e 100644 --- a/src/Whoops/Exception/Frame.php +++ b/src/Whoops/Exception/Frame.php @@ -199,12 +199,12 @@ class Frame implements Serializable */ public function serialize() { - $frames = $this->frames; + $frame = $this->frame; if(!empty($this->comments)) { - $frames['_comments'] = $this->comments; + $frame['_comments'] = $this->comments; } - return serialize($frames); + return serialize($frame); } /** @@ -216,13 +216,13 @@ class Frame implements Serializable */ public function unserialize($serializedFrame) { - $frames = unserialize($serializedFrame); + $frame = unserialize($serializedFrame); - if(!empty($frames['_comments'])) { - $this->comments = $frames['_comments']; - unset($frames['_comments']); + if(!empty($frame['_comments'])) { + $this->comments = $frame['_comments']; + unset($frame['_comments']); } - $this->frames = $frames; + $this->frame = $frame; } } diff --git a/tests/Whoops/Exception/FrameCollectionTest.php b/tests/Whoops/Exception/FrameCollectionTest.php new file mode 100644 index 0000000..8b5701a --- /dev/null +++ b/tests/Whoops/Exception/FrameCollectionTest.php @@ -0,0 +1,71 @@ + + */ + +namespace Whoops\Exception; +use Whoops\Exception\FrameCollection; +use Whoops\TestCase; +use Mockery as m; + +class FrameCollectionTest extends TestCase +{ + /** + * @return array + */ + private function getFrameData() + { + return array( + 'file' => __DIR__ . '/../../fixtures/frame.lines-test.php', + 'line' => 0, + 'function' => 'test', + 'class' => 'MyClass', + 'args' => array(true, 'hello') + ); + } + + /** + * @param array $frames + * @return Whoops\Exception\FrameCollection + */ + private function getFrameCollectionInstance($frames = null) + { + if($frames === null) { + $self = $this; + + // Get 10 frames + $frames = array_map(function() use($self) { + return $self->getFrameData(); + }, range(1, 10)); + } + + return new FrameCollection($frames); + } + + /** + * @covers Whoops\Exception\FrameCollection::getIterator + */ + public function testCollectionIsIterable() + { + $frames = $this->getFrameCollectionInstance(); + foreach($frames as $frame) { + $this->assertInstanceOf('Whoops\\Exception\\Frame', $frame); + } + } + + /** + * @covers Whoops\Exception\FrameCollection::serialize + * @covers Whoops\Exception\FrameCollection::unserialize + */ + public function testCollectionIsSerializable() + { + $frames = $this->getFrameCollectionInstance(); + $serializedFrames = serialize($frames); + $newFrames = unserialize($serializedFrames); + + foreach($newFrames as $frame) { + $this->assertInstanceOf('Whoops\\Exception\\Frame', $frame); + } + } +} diff --git a/tests/Whoops/Exception/FrameTest.php b/tests/Whoops/Exception/FrameTest.php index 2f53774..19d60b4 100644 --- a/tests/Whoops/Exception/FrameTest.php +++ b/tests/Whoops/Exception/FrameTest.php @@ -26,6 +26,7 @@ class FrameTest extends TestCase } /** + * @param array $data * @return Whoops\Exception\Frame */ private function getFrameInstance($data = null)