Code Duplication    Length = 45-48 lines in 2 locations

test/Unit/RandomLib/Mixer/HashTest.php 1 location

@@ 7-51 (lines=45) @@
4
5
use SecurityLib\Strength;
6
7
class HashTest extends \PHPUnit_Framework_TestCase {
8
9
    public static function provideMix() {
10
        $data = array(
11
            array(array(), ''),
12
            array(array('1', '1'), '0d'),
13
            array(array('a'), '61'),
14
            // This expects 'b' because of how the mock hmac function works
15
            array(array('a', 'b'), '9a'),
16
            array(array('aa', 'ba'), '6e84'),
17
            array(array('ab', 'bb'), 'b0cb'),
18
            array(array('aa', 'bb'), 'ae8d'),
19
            array(array('aa', 'bb', 'cc'), 'a14c'),
20
            array(array('aabbcc', 'bbccdd', 'ccddee'), 'a8aff3939934'),
21
        );
22
        return $data;
23
    }
24
25
    public function testConstructWithoutArgument() {
26
        $hash = new Hash;
27
        $this->assertTrue($hash instanceof \RandomLib\Mixer);
28
    }
29
30
    public function testGetStrength() {
31
        $strength = new Strength(Strength::MEDIUM);
32
        $actual = Hash::getStrength();
33
        $this->assertEquals($actual, $strength);
34
    }
35
36
    public function testTest() {
37
        $actual = Hash::test();
38
        $this->assertTrue($actual);
39
    }
40
41
    /**
42
     * @dataProvider provideMix
43
     */
44
    public function testMix($parts, $result) {
45
        $mixer = new Hash('md5');
46
        $actual = $mixer->mix($parts);
47
        $this->assertEquals($result, bin2hex($actual));
48
    }
49
50
51
}
52

test/Unit/RandomLib/Mixer/McryptRijndael128Test.php 1 location

@@ 7-54 (lines=48) @@
4
5
use SecurityLib\Strength;
6
7
class McryptRijndael128Test extends \PHPUnit_Framework_TestCase {
8
9
    public static function provideMix() {
10
        $data = array(
11
            array(array(), ''),
12
            array(array('', ''), ''),
13
            array(array('a'), '61'),
14
            array(array('a', 'b'), '6a'),
15
            array(array('aa', 'ba'), '688d'),
16
            array(array('ab', 'bb'), 'f8bc'),
17
            array(array('aa', 'bb'), 'a0f3'),
18
            array(array('aa', 'bb', 'cc'), '87c3'),
19
            array(array('aabbcc', 'bbccdd', 'ccddee'), '7cf2273e46c7'),
20
        );
21
        return $data;
22
    }
23
24
    protected function setUp() {
25
        if (!extension_loaded('mcrypt')) {
26
            $this->markTestSkipped('mcrypt extension is not available');
27
        }
28
    }
29
30
    public function testConstructWithoutArgument() {
31
        $hash = new McryptRijndael128;
32
        $this->assertTrue($hash instanceof \RandomLib\Mixer);
33
    }
34
35
    public function testGetStrength() {
36
        $strength = new Strength(Strength::HIGH);
37
        $actual = McryptRijndael128::getStrength();
38
        $this->assertEquals($actual, $strength);
39
    }
40
41
    public function testTest() {
42
        $actual = McryptRijndael128::test();
43
        $this->assertTrue($actual);
44
    }
45
46
    /**
47
     * @dataProvider provideMix
48
     */
49
    public function testMix($parts, $result) {
50
        $mixer = new McryptRijndael128;
51
        $actual = $mixer->mix($parts);
52
        $this->assertEquals($result, bin2hex($actual));
53
    }
54
}
55