HashTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 109
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testInit() 0 11 1
A testGetRaw() 0 16 1
A testGetHash() 0 17 1
A testValidate() 0 17 1
1
<?php
2
namespace Redaxscript\Tests;
3
4
use Redaxscript\Hash;
5
6
/**
7
 * HashTest
8
 *
9
 * @since 2.6.0
10
 *
11
 * @package Redaxscript
12
 * @category Tests
13
 * @author Henry Ruhs
14
 *
15
 * @covers Redaxscript\Hash
16
 */
17
18
class HashTest extends TestCaseAbstract
19
{
20
	/**
21
	 * testInit
22
	 *
23
	 * @since 2.6.0
24
	 *
25
	 * @param string $raw
26
	 *
27
	 * @dataProvider providerAutoloader
28
	 */
29
30
	public function testInit(string $raw = null) : void
31
	{
32
		/* setup */
33
34
		$hash = new Hash();
35
		$hash->init($raw);
36
37
		/* compare */
38
39
		$this->assertNotEquals($hash->getRaw(), $hash->getHash());
40
	}
41
42
	/**
43
	 * testGetRaw
44
	 *
45
	 * @since 2.6.0
46
	 *
47
	 * @param string $raw
48
	 *
49
	 * @dataProvider providerAutoloader
50
	 */
51
52
	public function testGetRaw(string $raw = null) : void
53
	{
54
		/* setup */
55
56
		$hash = new Hash();
57
		$hash->init($raw);
58
59
		/* expect and actual */
60
61
		$expect = $raw;
62
		$actual = $hash->getRaw();
63
64
		/* compare */
65
66
		$this->assertEquals($expect, $actual);
67
	}
68
69
	/**
70
	 * testGetHash
71
	 *
72
	 * @since 4.3.0
73
	 *
74
	 * @param string $raw
75
	 * @param array $hashArray
76
	 *
77
	 * @dataProvider providerAutoloader
78
	 */
79
80
	public function testGetHash(string $raw = null, array $hashArray = []) : void
81
	{
82
		/* setup */
83
84
		$hash = new Hash();
85
		$hash->init($raw);
86
		$hashAlgorithm = $hash->getAlgorithm();
87
88
		/* expect and actual */
89
90
		$expect = $hashArray[$hashAlgorithm][0];
91
		$actual = $hash->getHash();
92
93
		/* compare */
94
95
		$this->assertStringStartsWith($expect, $actual);
96
	}
97
98
	/**
99
	 * testValidate
100
	 *
101
	 * @since 4.3.0
102
	 *
103
	 * @param string $raw
104
	 * @param array $hashArray
105
	 *
106
	 * @dataProvider providerAutoloader
107
	 */
108
109
	public function testValidate(string $raw = null, array $hashArray = []) : void
110
	{
111
		/* setup */
112
113
		$hash = new Hash();
114
		$hash->init($raw);
115
		$hashAlgorithm = $hash->getAlgorithm();
116
117
		/* expect and actual */
118
119
		$expect = $hashArray[$hashAlgorithm][1];
120
		$actual = $hash->validate($raw, $expect);
121
122
		/* compare */
123
124
		$this->assertTrue($actual);
125
	}
126
}
127