Fix FiltersCollection::getIterator in case of empty collection

This commit is contained in:
Romain Neutron 2013-09-05 11:12:10 +02:00
commit e43da86152
2 changed files with 12 additions and 2 deletions

View file

@ -47,8 +47,12 @@ class FiltersCollection implements \Countable, \IteratorAggregate
public function getIterator()
{
if (null === $this->sorted) {
krsort($this->filters);
$this->sorted = call_user_func_array('array_merge', $this->filters);
if (0 === count($this->filters)) {
$this->sorted = $this->filters;
} else {
krsort($this->filters);
$this->sorted = call_user_func_array('array_merge', $this->filters);
}
}
return new \ArrayIterator($this->sorted);

View file

@ -30,6 +30,12 @@ class FiltersCollectionTest extends TestCase
$this->assertCount(2, $coll->getIterator());
}
public function testEmptyIterator()
{
$coll = new FiltersCollection();
$this->assertInstanceOf('\ArrayIterator', $coll->getIterator());
}
public function testIteratorSort()
{
$coll = new FiltersCollection();