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$iterations = getenv("SKIP_SLOW_TESTS") ? 3_000 : 10_000;
16
17foreach ($engines as $engine) {
18    echo $engine::class, PHP_EOL;
19
20    for ($i = 0; $i < 10_000; $i++) {
21        $engine->generate();
22    }
23
24    $engine2 = unserialize(serialize($engine));
25
26    for ($i = 0; $i < $iterations; $i++) {
27        if ($engine->generate() !== $engine2->generate()) {
28            die("failure: state differs at {$i}");
29        }
30    }
31}
32
33die('success');
34
35?>
36--EXPECT--
37Random\Engine\Test\TestCountingEngine32
38Random\Engine\Test\TestShaEngine
39success
40