/
EntityTest.php
103 lines (80 loc) · 2.55 KB
/
EntityTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
namespace MardyHmacTest;
use Mardy\Hmac\Entity;
use PHPUnit\Framework\TestCase;
class EntityTest extends TestCase
{
/**
* @var Entity
*/
protected $entity;
public function setup(): void
{
$this->entity = new Entity;
}
/**
* Testing all the getters and setters in the entity class
*/
public function testGettersAndSetters()
{
$array = $this->getDummyHmacData();
$this->entity->setData($array['data']);
$this->entity->setKey($array['key']);
$this->entity->setTime($array['time']);
$this->entity->setHmac($array['hmac']);
$this->assertTrue($array['data'] === $this->entity->getData());
$this->assertTrue($array['key'] === $this->entity->getKey());
$this->assertTrue($array['time'] === $this->entity->getTime());
$this->assertTrue($array['hmac'] === $this->entity->getHmac());
}
/**
* Testing the isEncodable method
*/
public function testIsEncodable()
{
$array = $this->getDummyHmacData();
$this->assertFalse($this->entity->isEncodable());
$this->entity->setData($array['data']);
$this->entity->setKey($array['key']);
$this->entity->setTime($array['time']);
$this->assertTrue($this->entity->isEncodable());
}
/**
* Testing the isEncoded method
*/
public function testIsEncoded()
{
$array = $this->getDummyHmacData();
$this->assertFalse($this->entity->isEncoded());
$this->entity->setHmac($array['hmac']);
$this->assertTrue($this->entity->isEncoded());
}
/**
* Testing the toArray method
*/
public function testToArray()
{
$array = $this->getDummyHmacData();
$this->assertFalse($this->entity->toArray());
$this->entity->setData($array['data']);
$this->entity->setHmac($array['hmac']);
$this->entity->setTime($array['time']);
unset($array['key']);
$this->assertSame($array, $this->entity->toArray());
}
/**
* Gets a dummy HMAC array
*
* @return array
*/
protected function getDummyHmacData()
{
$array = [];
$array['data'] = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 30);
$array['key'] = hash('sha512', rand(1000, 100000));
$array['time'] = time();
//doesn't really matter about it only being a random string, this is only a test!
$array['hmac'] = hash('sha512', rand(1000, 100000));
return $array;
}
}