-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathTypeTest.php
More file actions
121 lines (96 loc) · 3.04 KB
/
Copy pathTypeTest.php
File metadata and controls
121 lines (96 loc) · 3.04 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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
namespace BNETDocs\Tests\Libraries\Server;
use \BNETDocs\Libraries\Server\Type;
use \OutOfBoundsException;
use \PHPUnit\Framework\TestCase;
use \stdClass;
class TypeTest extends TestCase
{
private Type $type;
protected function setUp(): void
{
// null id → allocate() sets label='' and returns true early; no DB access.
$this->type = new Type(null);
}
// Default state after null construction
public function testDefaultIdIsNull(): void
{
$this->assertNull($this->type->getId());
}
public function testDefaultLabelIsEmpty(): void
{
$this->assertSame('', $this->type->getLabel());
}
// StdClass construction path
public function testStdClassConstructionSetsFields(): void
{
$obj = new stdClass();
$obj->id = 3;
$obj->label = 'Battle.net Chat';
$t = new Type($obj);
$this->assertSame(3, $t->getId());
$this->assertSame('Battle.net Chat', $t->getLabel());
}
// setLabel validation
public function testSetLabelEmptyStringIsAllowed(): void
{
$this->type->setLabel('');
$this->assertSame('', $this->type->getLabel());
}
public function testSetLabelAtMaxLengthIsAllowed(): void
{
$value = str_repeat('x', Type::MAX_LABEL);
$this->type->setLabel($value);
$this->assertSame($value, $this->type->getLabel());
}
public function testSetLabelTooLongThrowsOutOfBounds(): void
{
$this->expectException(OutOfBoundsException::class);
$this->type->setLabel(str_repeat('x', Type::MAX_LABEL + 1));
}
public function testSetLabelChangesValue(): void
{
$this->type->setLabel('BNLS');
$this->assertSame('BNLS', $this->type->getLabel());
}
// setId validation
public function testSetIdNullIsAllowed(): void
{
$this->type->setId(null);
$this->assertNull($this->type->getId());
}
public function testSetIdPositiveIsAllowed(): void
{
$this->type->setId(7);
$this->assertSame(7, $this->type->getId());
}
public function testSetIdNegativeThrowsOutOfBounds(): void
{
$this->expectException(OutOfBoundsException::class);
$this->type->setId(-1);
}
// DB-free early-exit
public function testDeallocateReturnsFalseWhenIdIsNull(): void
{
$this->assertFalse($this->type->deallocate());
}
// jsonSerialize
public function testJsonSerializeHasExpectedKeys(): void
{
$data = $this->type->jsonSerialize();
$this->assertArrayHasKey('id', $data);
$this->assertArrayHasKey('label', $data);
}
public function testJsonSerializeDefaultValues(): void
{
$data = $this->type->jsonSerialize();
$this->assertNull($data['id']);
$this->assertSame('', $data['label']);
}
public function testJsonSerializeReflectsSetValues(): void
{
$this->type->setLabel('BNLS');
$data = $this->type->jsonSerialize();
$this->assertSame('BNLS', $data['label']);
}
}