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

Fix SplPriorityQueue::$serial not being reset after serialization #92

Merged
merged 5 commits into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#92](https://github.com/zendframework/zend-stdlib/pull/92) Fix SplPriorityQueue::$serial not being reset after serialization.

## 3.2.0 - 2018-04-30

Expand Down
2 changes: 2 additions & 0 deletions src/SplPriorityQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ public function serialize()
*/
public function unserialize($data)
{
$this->serial = PHP_INT_MAX;
foreach (unserialize($data) as $item) {
$this->serial--;
$this->insert($item['data'], $item['priority']);
}
}
Expand Down
21 changes: 8 additions & 13 deletions test/SplPriorityQueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,15 @@ public function testSerializationAndDeserializationShouldMaintainState()
{
$s = serialize($this->queue);
$unserialized = unserialize($s);
$count = count($this->queue);
$this->assertSame(
$count,
count($unserialized),
'Expected count ' . $count . '; received ' . count($unserialized)
);

$expected = iterator_to_array($this->queue);
$test = iterator_to_array($unserialized);
$this->assertSame(
$expected,
$test,
'Expected: ' . var_export($expected, 1) . "\nReceived:" . var_export($test, 1)
);
// assert same size
$this->assertSameSize($this->queue, $unserialized);

// assert same values
$this->assertSame(iterator_to_array($this->queue), iterator_to_array($unserialized));

// assert equal
$this->assertEquals($this->queue, $unserialized);
}

public function testCanRetrieveQueueAsArray()
Expand Down