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

Commit 929dba4

Browse files
committed
Merge pull request #92 from azjezz/patch-1
Fix SplPriorityQueue::$serial not being reset after serialization Conflicts: CHANGELOG.md
2 parents 818a81c + 7035b4e commit 929dba4

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ All notable changes to this project will be documented in this file, in reverse
2222

2323
### Fixed
2424

25+
- [#92](https://github.com/zendframework/zend-stdlib/pull/92) fixes serialization of `SplPriorityQueue` by ensuring its `$serial`
26+
property is also serialized.
27+
2528
- [#91](https://github.com/zendframework/zend-stdlib/pull/91) fixes behavior in the `ArrayObject` implementation that was not
2629
compatible with PHP 7.3.
2730

src/SplPriorityQueue.php

+2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ public function serialize()
8484
*/
8585
public function unserialize($data)
8686
{
87+
$this->serial = PHP_INT_MAX;
8788
foreach (unserialize($data) as $item) {
89+
$this->serial--;
8890
$this->insert($item['data'], $item['priority']);
8991
}
9092
}

test/SplPriorityQueueTest.php

+8-13
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,15 @@ public function testSerializationAndDeserializationShouldMaintainState()
4848
{
4949
$s = serialize($this->queue);
5050
$unserialized = unserialize($s);
51-
$count = count($this->queue);
52-
$this->assertSame(
53-
$count,
54-
count($unserialized),
55-
'Expected count ' . $count . '; received ' . count($unserialized)
56-
);
5751

58-
$expected = iterator_to_array($this->queue);
59-
$test = iterator_to_array($unserialized);
60-
$this->assertSame(
61-
$expected,
62-
$test,
63-
'Expected: ' . var_export($expected, 1) . "\nReceived:" . var_export($test, 1)
64-
);
52+
// assert same size
53+
$this->assertSameSize($this->queue, $unserialized);
54+
55+
// assert same values
56+
$this->assertSame(iterator_to_array($this->queue), iterator_to_array($unserialized));
57+
58+
// assert equal
59+
$this->assertEquals($this->queue, $unserialized);
6560
}
6661

6762
public function testCanRetrieveQueueAsArray()

0 commit comments

Comments
 (0)