3 // this is in the same namespace as Crypto for mocking 'rand' and 'random_init'
4 namespace Friendica\Util;
6 use PHPUnit\Framework\TestCase;
8 class CryptoTest extends TestCase
11 * Replaces random_int results with given mocks
14 private function assertRandomInt($min, $max)
17 $phpMock['random_int'] = function($mMin, $mMax) use ($min, $max) {
18 $this->assertEquals($min, $mMin);
19 $this->assertEquals($max, $mMax);
24 public function testRandomDigitsRandomInt()
26 $this->assertRandomInt(0, 9);
28 $test = Crypto::randomDigits(1);
29 $this->assertEquals(1, strlen($test));
30 $this->assertEquals(1, $test);
32 $test = Crypto::randomDigits(8);
33 $this->assertEquals(8, strlen($test));
34 $this->assertEquals(11111111, $test);
39 * A workaround to replace the PHP native random_int() (>= 7.0) with a mocked function
43 function random_int($min, $max)
46 if (isset($phpMock['random_int'])) {
47 $result = call_user_func_array($phpMock['random_int'], func_get_args());