Completed
Push — master ( 3d39f9...d9b5c0 )
by Anthony
07:02 queued 04:32
created

URandomTest::testGenerate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
nc 2
cc 2
eloc 8
nop 2
1
<?php
2
3
namespace RandomLib\Source;
4
5
use SecurityLib\Strength;
6
7
8
9
class URandomTest extends \PHPUnit_Framework_TestCase {
10
11
    public static function provideGenerate() {
12
        $data = array();
13
        for ($i = 0; $i < 10; $i += 5) {
14
            $not = $i > 0 ? str_repeat(chr(0), $i) : chr(0);
15
            $data[] = array($i, $not);
16
        }
17
        return $data;
18
    }
19
20
    /**
21
     */
22
    public function testGetStrength() {
23
        $strength = new Strength(Strength::MEDIUM);
24
        $actual = URandom::getStrength();
25
        $this->assertEquals($actual, $strength);
26
    }
27
28
    /**
29
     * @dataProvider provideGenerate
30
     * @group slow
31
     */
32
    public function testGenerate($length, $not) {
33
        $rand = new URandom;
34
        $stub = $rand->generate($length);
35
        $this->assertEquals($length, strlen($stub));
36
        if (file_exists('/dev/urandom')) {
37
            $this->assertNotEquals($not, $stub);
38
        } else {
39
            $this->assertEquals(str_repeat(chr(0), $length), $stub);
40
        }
41
    }
42
43
}
44