Completed
Push — master ( d5c6c4...a11ecc )
by Michael
10s
created

FactoryTest::testNoAvailableSource()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * The RandomLib library for securely generating random numbers and strings in PHP
5
 *
6
 * @author     Anthony Ferrara <[email protected]>
7
 * @copyright  2011 The Authors
8
 * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
9
 * @version    Build @@version@@
10
 */
11
namespace RandomLib;
12
13
use SecurityLib\Strength;
14
15
class FactoryTest extends \PHPUnit_Framework_TestCase
16
{
17
    public function testConstruct()
18
    {
19
        $factory = new Factory();
20
        $this->assertTrue($factory instanceof Factory);
21
    }
22
23
    public function testGetGeneratorFallback()
24
    {
25
        $factory = new Factory();
26
        $generator = $factory->getGenerator(new Strength(Strength::VERYLOW));
27
        $mixer = call_user_func(array(
28
            get_class($generator->getMixer()),
29
            'getStrength',
30
        ));
31
        $this->assertTrue($mixer->compare(new Strength(Strength::VERYLOW)) <= 0);
32
    }
33
34
    /**
35
     * @covers RandomLib\Factory::getMediumStrengthGenerator
36
     * @covers RandomLib\Factory::getGenerator
37
     * @covers RandomLib\Factory::findMixer
38
     * @covers RandomLib\Factory::findSources
39
     */
40
    public function testGetMediumStrengthGenerator()
41
    {
42
        $factory = new Factory();
43
        $generator = $factory->getMediumStrengthGenerator();
44
        $this->assertTrue($generator instanceof Generator);
45
        $mixer = call_user_func(array(
46
            get_class($generator->getMixer()),
47
            'getStrength',
48
        ));
49
        $this->assertTrue($mixer->compare(new Strength(Strength::MEDIUM)) <= 0);
50
        foreach ($generator->getSources() as $source) {
51
            $strength = call_user_func(array(get_class($source), 'getStrength'));
52
            $this->assertTrue($strength->compare(new Strength(Strength::MEDIUM)) >= 0);
53
        }
54
    }
55
56
    /**
57
     * @expectedException RuntimeException
58
     * @expectedExceptionMessage Could not find sources
59
     */
60
    public function testNoAvailableSource()
61
    {
62
        $factory = new Factory();
63
        $sources = new \ReflectionProperty($factory, 'sources');
64
        $sources->setAccessible(true);
65
        $sources->setValue($factory, array());
66
        $factory->getMediumStrengthGenerator();
67
    }
68
}
69