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

MTRandTest::testGenerate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 6
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 6
loc 6
rs 9.4285
nc 1
cc 1
eloc 5
nop 2
1
<?php
2
3
namespace RandomLib\Source;
4
5
use SecurityLib\Strength;
6
7
8
9
class MTRandTest extends \PHPUnit_Framework_TestCase {
10
11
    public static function provideGenerate() {
12
        $data = array();
13
        for ($i = 0; $i < 100; $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
        if (defined('S_ALL')) {
24
            $strength = new Strength(Strength::MEDIUM);
25
        } else {
26
            $strength = new Strength(Strength::LOW);
27
        }
28
        $actual = MTRand::getStrength();
29
        $this->assertEquals($actual, $strength);
30
    }
31
32
    /**
33
     * @dataProvider provideGenerate
34
     */
35
    public function testGenerate($length, $not) {
36
        $rand = new MTRand;
37
        $stub = $rand->generate($length);
38
        $this->assertEquals($length, strlen($stub));
39
        $this->assertNotEquals($not, $stub);
40
    }
41
42
}
43