1--TEST--
2Random: Engine: Serialization of user engines must preserve the sequence
3--FILE--
4<?php
5
6use Random\Engine;
7use Random\Engine\Test\TestShaEngine;
8
9require __DIR__ . "/../engines.inc";
10
11final class CountingEngine32 implements Engine
12{
13    private int $count = 0;
14
15    public function generate(): string
16    {
17        return pack('V', ++$this->count);
18    }
19}
20
21$engines = [];
22$engines[] = new CountingEngine32();
23$engines[] = new TestShaEngine();
24
25foreach ($engines as $engine) {
26    echo $engine::class, PHP_EOL;
27
28    for ($i = 0; $i < 10_000; $i++) {
29        $engine->generate();
30    }
31
32    $engine2 = unserialize(serialize($engine));
33
34    for ($i = 0; $i < 10_000; $i++) {
35        if ($engine->generate() !== $engine2->generate()) {
36            die("failure: state differs at {$i}");
37        }
38    }
39}
40
41die('success');
42
43?>
44--EXPECT--
45CountingEngine32
46Random\Engine\Test\TestShaEngine
47success
48