mirror of
https://github.com/filp/whoops.git
synced 2026-09-13 03:06:20 +00:00
FrameCollection: implements ArrayAccess
This commit is contained in:
@@ -9,6 +9,7 @@ use Whoops\Exception\Frame;
|
||||
use UnexpectedValueException;
|
||||
use IteratorAggregate;
|
||||
use ArrayIterator;
|
||||
use ArrayAccess;
|
||||
use Serializable;
|
||||
use Countable;
|
||||
|
||||
@@ -16,7 +17,7 @@ use Countable;
|
||||
* Exposes a fluent interface for dealing with an ordered list
|
||||
* of stack-trace frames.
|
||||
*/
|
||||
class FrameCollection implements IteratorAggregate, Serializable, Countable
|
||||
class FrameCollection implements ArrayAccess, IteratorAggregate, Serializable, Countable
|
||||
{
|
||||
/**
|
||||
* @var array[]
|
||||
@@ -93,6 +94,42 @@ class FrameCollection implements IteratorAggregate, Serializable, Countable
|
||||
return new ArrayIterator($this->frames);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArrayAccess::offsetExists
|
||||
* @param int $offset
|
||||
*/
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
return isset($this->frames[$offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArrayAccess::offsetGet
|
||||
* @param int $offset
|
||||
*/
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
return $this->frames[$offset];
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArrayAccess::offsetSet
|
||||
* @param int $offset
|
||||
*/
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
throw new \Exception(__CLASS__ . ' is read only');
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArrayAccess::offsetUnset
|
||||
* @param int $offset
|
||||
*/
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
throw new \Exception(__CLASS__ . ' is read only');
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Countable::count
|
||||
* @return int
|
||||
|
||||
@@ -61,6 +61,44 @@ class FrameCollectionTest extends TestCase
|
||||
return new FrameCollection($frames);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\FrameCollection::offsetExists
|
||||
*/
|
||||
public function testArrayAccessExists()
|
||||
{
|
||||
$collection = $this->getFrameCollectionInstance();
|
||||
$this->assertTrue(isset($collection[0]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\FrameCollection::offsetGet
|
||||
*/
|
||||
public function testArrayAccessGet()
|
||||
{
|
||||
$collection = $this->getFrameCollectionInstance();
|
||||
$this->assertInstanceOf('Whoops\\Exception\\Frame', $collection[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\FrameCollection::offsetSet
|
||||
* @expectedException Exception
|
||||
*/
|
||||
public function testArrayAccessSet()
|
||||
{
|
||||
$collection = $this->getFrameCollectionInstance();
|
||||
$collection[0] = 'foo';
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\FrameCollection::offsetUnset
|
||||
* @expectedException Exception
|
||||
*/
|
||||
public function testArrayAccessUnset()
|
||||
{
|
||||
$collection = $this->getFrameCollectionInstance();
|
||||
unset($collection[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\FrameCollection::filter
|
||||
* @covers Whoops\Exception\FrameCollection::count
|
||||
|
||||
Reference in New Issue
Block a user