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

Commit

Permalink
Merge pull request #92 from azjezz/patch-1
Browse files Browse the repository at this point in the history
Fix SplPriorityQueue::$serial not being reset after serialization

Conflicts:
	CHANGELOG.md
  • Loading branch information
weierophinney committed Aug 28, 2018
2 parents 818a81c + 7035b4e commit 929dba4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- [#92](https://github.com/zendframework/zend-stdlib/pull/92) fixes serialization of `SplPriorityQueue` by ensuring its `$serial`
property is also serialized.

- [#91](https://github.com/zendframework/zend-stdlib/pull/91) fixes behavior in the `ArrayObject` implementation that was not
compatible with PHP 7.3.

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

0 comments on commit 929dba4

Please sign in to comment.