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/9'
Browse files Browse the repository at this point in the history
Close #9
  • Loading branch information
weierophinney committed Jul 21, 2015
2 parents 0da8762 + ecf703b commit 077ebe7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/PriorityList.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ class PriorityList implements Iterator, Countable
*/
public function insert($name, $value, $priority = 0)
{
if (!isset($this->items[$name])) {
$this->count++;
}

$this->sorted = false;
$this->count++;

$this->items[$name] = [
'data' => $value,
Expand Down
18 changes: 18 additions & 0 deletions test/PriorityListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ public function testInsert()
}
}

public function testInsertDuplicates()
{
$this->list->insert('foo', new \stdClass());
$this->list->insert('bar', new \stdClass());

$this->assertEquals(2, count($this->list));

$this->list->insert('foo', new \stdClass());
$this->list->insert('foo', new \stdClass());
$this->list->insert('bar', new \stdClass());

$this->assertEquals(2, count($this->list));

$this->list->remove('foo');

$this->assertEquals(1, count($this->list));
}

public function testRemove()
{
$this->list->insert('foo', new \stdClass(), 0);
Expand Down

0 comments on commit 077ebe7

Please sign in to comment.