1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace RandomLib\Mixer; |
4
|
|
|
|
5
|
|
|
use SecurityLib\Strength; |
6
|
|
|
|
7
|
|
View Code Duplication |
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
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.