1--TEST-- 2Random: Randomizer: Engines returning an empty string are detected and rejected 3--FILE-- 4<?php 5 6use Random\Engine; 7use Random\Randomizer; 8 9final class EmptyStringEngine implements Engine 10{ 11 public function generate(): string 12 { 13 return ''; 14 } 15} 16 17function randomizer(): Randomizer 18{ 19 return new Randomizer(new EmptyStringEngine()); 20} 21 22try { 23 var_dump(randomizer()->getInt(0, 1234)); 24} catch (Random\BrokenRandomEngineError $e) { 25 echo $e->getMessage(), PHP_EOL; 26} 27 28try { 29 var_dump(randomizer()->nextInt()); 30} catch (Random\BrokenRandomEngineError $e) { 31 echo $e->getMessage(), PHP_EOL; 32} 33 34try { 35 var_dump(bin2hex(randomizer()->getBytes(1))); 36} catch (Random\BrokenRandomEngineError $e) { 37 echo $e->getMessage(), PHP_EOL; 38} 39 40try { 41 var_dump(randomizer()->shuffleArray(range(1, 1234))); 42} catch (Random\BrokenRandomEngineError $e) { 43 echo $e->getMessage(), PHP_EOL; 44} 45 46try { 47 var_dump(randomizer()->pickArrayKeys(range(1, 1234), 1)); 48} catch (Random\BrokenRandomEngineError $e) { 49 echo $e->getMessage(), PHP_EOL; 50} 51 52try { 53 var_dump(randomizer()->pickArrayKeys(range(1, 1234), 10)); 54} catch (Random\BrokenRandomEngineError $e) { 55 echo $e->getMessage(), PHP_EOL; 56} 57 58try { 59 var_dump(randomizer()->shuffleBytes('foobar')); 60} catch (Random\BrokenRandomEngineError $e) { 61 echo $e->getMessage(), PHP_EOL; 62} 63 64?> 65--EXPECT-- 66A random engine must return a non-empty string 67A random engine must return a non-empty string 68A random engine must return a non-empty string 69A random engine must return a non-empty string 70A random engine must return a non-empty string 71A random engine must return a non-empty string 72A random engine must return a non-empty string 73