-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathEntityTest.php
More file actions
66 lines (51 loc) · 1.51 KB
/
EntityTest.php
File metadata and controls
66 lines (51 loc) · 1.51 KB
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
<?php
namespace EquipTests\Data;
class EntityTest extends \PHPUnit_Framework_TestCase
{
/**
* @var array
*/
protected $data;
/**
* @var \Equip\Data\EntityInterface
*/
protected $entity;
public function setUp()
{
$this->data = [
'id' => 42,
'name' => 'Life',
'created_at' => '2015-10-31 11:10:33',
];
$this->entity = new Entity($this->data);
}
public function testImplements()
{
$this->assertInstanceOf('Equip\Data\EntityInterface', $this->entity);
$this->assertInstanceOf('JsonSerializable', $this->entity);
$this->assertInstanceOf('Serializable', $this->entity);
}
public function testToArray()
{
$this->assertSame($this->data, $this->entity->toArray());
}
public function testDate()
{
$this->assertInstanceOf('Cake\Chronos\Chronos', $this->entity->date('created_at'));
}
public function testJsonEncode()
{
$json = json_encode($this->entity);
$this->assertJson($json);
$this->assertSame($this->data, json_decode($json, true));
}
public function testSerialize()
{
$frozen = serialize($this->entity);
$this->assertInternalType('string', $frozen);
$thawed = unserialize($frozen);
$this->assertInstanceOf(get_class($this->entity), $thawed);
$this->assertNotSame($this->entity, $thawed);
$this->assertSame($this->data, $thawed->toArray());
}
}