Fix FiltersCollection::getIterator in case of empty collection
This commit is contained in:
parent
1de948faba
commit
e43da86152
2 changed files with 12 additions and 2 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue