/var/www/hkosl.com/littleark/webadmin/libraies/phpseclib/phpseclib/tests/Unit/Crypt/RandomTest.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/**
 * @author    Andreas Fischer <bantu@phpbb.com>
 * @copyright 2014 Andreas Fischer
 * @license   http://www.opensource.org/licenses/mit-license.html  MIT License
 */

class Unit_Crypt_RandomTest extends PhpseclibTestCase
{
    public function 
stringLengthData()
    {
        return 
array_map(array($this'wrap'), array(
            
12345678910111317192023293137,
            
414347535961677173798389971111281000,
            
10241000012345100000123456
        
));
    }

    
/** @dataProvider stringLengthData */
    
public function testStringLength($length)
    {
        
$this->assertSame(
            
$length,
            
strlen(crypt_random_string($length)),
            
'Failed asserting that a string of expected length was generated.'
        
);
    }

    
/**
    * Takes a set of random values of length 128 bits and asserts all taken
    * values are unique.
    */
    
public function testStringUniqueness()
    {
        
$values = array();
        for (
$i 0$i 10000; ++$i) {
            
$rand crypt_random_string(16);
            
$this->assertSame(16strlen($rand));
            
$this->assertArrayNotHasKey(
                
$rand,
                
$values,
                
'Failed asserting that generated value does not exist in set.'
            
);
            
$values[$rand] = true;
        }
    }

    protected function 
wrap($x)
    {
        
// array() is not a function, but $this->wrap() is.
        
return array($x);
    }
}