1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Blackmine\Tests\Model; |
4
|
|
|
|
5
|
|
|
use Blackmine\Model\NamedIdentity; |
6
|
|
|
|
7
|
|
|
class NamedIdentityTest extends AbstractModelTest |
8
|
|
|
{ |
9
|
|
|
public const TEST_MODEL = NamedIdentity::class; |
10
|
|
|
|
11
|
|
|
public function testConstructor(): void |
12
|
|
|
{ |
13
|
|
|
$identity = new NamedIdentity(id: 1, name: "Test"); |
14
|
|
|
$this->assertEquals(1, $identity->getId()); |
15
|
|
|
$this->assertEquals("Test", $identity->getName()); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function testFromArray(): void |
19
|
|
|
{ |
20
|
|
|
$identity = (new NamedIdentity())->fromArray(["id" => 1, "name" => "Test"]); |
21
|
|
|
$this->assertEquals(1, $identity->getId()); |
22
|
|
|
$this->assertEquals("Test", $identity->getName()); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testToArray(): void |
26
|
|
|
{ |
27
|
|
|
$expected = ["id" => 1, "name" => "Test"]; |
28
|
|
|
$identity = new NamedIdentity(1, "Test"); |
29
|
|
|
|
30
|
|
|
$this->assertEquals($expected, $identity->toArray()); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @throws \JsonException |
35
|
|
|
*/ |
36
|
|
|
public function testToJson(): void |
37
|
|
|
{ |
38
|
|
|
$expected = json_encode(["id" => 1, "name" => "Test"], JSON_THROW_ON_ERROR); |
39
|
|
|
$identity = new NamedIdentity(1, "Test"); |
40
|
|
|
|
41
|
|
|
$this->assertJsonStringEqualsJsonString($expected, $identity->toJson()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testJsonSerialize(): void |
45
|
|
|
{ |
46
|
|
|
$expected = ["id" => 1, "name" => "Test"]; |
47
|
|
|
$identity = new NamedIdentity(1, "Test"); |
48
|
|
|
|
49
|
|
|
$this->assertEquals($expected, $identity->jsonSerialize()); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @throws \JsonException |
54
|
|
|
*/ |
55
|
|
|
public function testJsonEncode(): void |
56
|
|
|
{ |
57
|
|
|
$expected = json_encode(["id" => 1, "name" => "Test"], JSON_THROW_ON_ERROR); |
58
|
|
|
$identity = new NamedIdentity(1, "Test"); |
59
|
|
|
|
60
|
|
|
$this->assertJsonStringEqualsJsonString($expected, json_encode($identity, JSON_THROW_ON_ERROR)); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testPayload(): void |
64
|
|
|
{ |
65
|
|
|
$identity = new NamedIdentity(1, "Test"); |
66
|
|
|
$this->expectError(); |
67
|
|
|
$this->expectErrorMessage('Mandatory constant ENTITY_NAME not defined in model class: ' . NamedIdentity::class); |
68
|
|
|
|
69
|
|
|
$identity->getPayload(); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|