Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/zendframework/zendframework#6242-stdlib/Priority…
Browse files Browse the repository at this point in the history
…List/fixCurrentAndIterator' into develop

Close zendframework/zendframework#6242
  • Loading branch information
Ocramius committed Jul 27, 2014
9 parents dc20608 + d8f58fd + c8aca84 + 4ac816f + 7f2fed2 + b528fc5 + fb851e2 + 802bf45 + 7718368 commit ea9af3c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/PriorityList.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ public function rewind()
*/
public function current()
{
$this->sorted || $this->sort();
$node = current($this->items);
return ($node !== false ? $node['data'] : false);
}
Expand All @@ -204,6 +205,7 @@ public function current()
*/
public function key()
{
$this->sorted || $this->sort();
return key($this->items);
}

Expand All @@ -230,6 +232,14 @@ public function valid()
return ($this->current() !== false);
}

/**
* @return self
*/
public function getIterator()
{
return clone $this;
}

/**
* count(): defined by Countable interface.
*
Expand Down
20 changes: 20 additions & 0 deletions test/PriorityListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,26 @@ public function testPriorityWithNegativesAndNull()
$this->assertEquals(array('bar', 'foo', 'baz'), $orders);
}

public function testCurrent()
{
$this->list->insert('foo', 'foo_value', null);
$this->list->insert('bar', 'bar_value', 1);
$this->list->insert('baz', 'baz_value', -1);

$this->assertEquals('bar', $this->list->key());
$this->assertEquals('bar_value', $this->list->current());
}

public function testIterator()
{
$this->list->insert('foo', 'foo_value');
$iterator = $this->list->getIterator();
$this->assertEquals($iterator, $this->list);

$this->list->insert('bar', 'bar_value');
$this->assertNotEquals($iterator, $this->list);
}

public function testToArray()
{
$this->list->insert('foo', 'foo_value', null);
Expand Down

0 comments on commit ea9af3c

Please sign in to comment.