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