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

MicroTimeTest::provideGenerate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
nc 3
cc 3
eloc 6
nop 0
1
<?php
2
3
namespace RandomLib\Source;
4
5
use SecurityLib\Strength;
6
7
8
9
class MicroTimeTest 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
     * Test the initialization of the static counter (!== 0)
22
     */
23
    public function testCounterNotNull() {
24
        $rand = new MicroTime;
25
        $reflection_class = new \ReflectionClass("RandomLib\Source\MicroTime");
26
        $static = $reflection_class->getStaticProperties();
27
        $this->assertTrue($static['counter'] !== 0);
28
    }
29
    
30
    /**
31
     */
32
    public function testGetStrength() {
33
        $strength = new Strength(Strength::VERYLOW);
34
        $actual = MicroTime::getStrength();
35
        $this->assertEquals($actual, $strength);
36
    }
37
38
    /**
39
     * @dataProvider provideGenerate
40
     */
41
    public function testGenerate($length, $not) {
42
        $rand = new MicroTime;
43
        $stub = $rand->generate($length);
44
        $this->assertEquals($length, strlen($stub));
45
        $this->assertNotEquals($not, $stub);
46
    }
47
48
}
49