Passed
Push — main ( 788641...5bbbb9 )
by Diego
02:40
created

NamedIdentityTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
c 1
b 0
f 0
dl 0
loc 66
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testToJson() 0 6 1
A testPayload() 0 7 1
A testConstructor() 0 5 1
A testToArray() 0 6 1
A testFromArray() 0 5 1
A testJsonSerialize() 0 6 1
A testJsonEncode() 0 6 1
1
<?php
2
3
namespace Blackmine\Tests\Models;
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
    /**
35
     * @throws \JsonException
36
     */
37
    public function testToJson(): void
38
    {
39
        $expected = json_encode(["id" => 1, "name" => "Test"], JSON_THROW_ON_ERROR);
40
        $identity = new NamedIdentity(1, "Test");
41
42
        $this->assertJsonStringEqualsJsonString($expected, $identity->toJson());
43
    }
44
45
    public function testJsonSerialize(): void
46
    {
47
        $expected = ["id" => 1, "name" => "Test"];
48
        $identity = new NamedIdentity(1, "Test");
49
50
        $this->assertEquals($expected, $identity->jsonSerialize());
51
52
    }
53
54
    /**
55
     * @throws \JsonException
56
     */
57
    public function testJsonEncode(): void
58
    {
59
        $expected = json_encode(["id" => 1, "name" => "Test"], JSON_THROW_ON_ERROR);
60
        $identity = new NamedIdentity(1, "Test");
61
62
        $this->assertJsonStringEqualsJsonString($expected, json_encode($identity, JSON_THROW_ON_ERROR));
63
64
    }
65
66
    public function testPayload(): void
67
    {
68
        $identity = new NamedIdentity(1, "Test");
69
        $this->expectError();
70
        $this->expectErrorMessage('Mandatory constant ENTITY_NAME not defined in model class: ' . NamedIdentity::class);
71
72
        $identity->getPayload();
73
    }
74
75
}
76