-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathProductTest.php
More file actions
121 lines (98 loc) · 3.33 KB
/
Copy pathProductTest.php
File metadata and controls
121 lines (98 loc) · 3.33 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;
use \BNETDocs\Libraries\Product;
use \PHPUnit\Framework\TestCase;
use \stdClass;
class ProductTest extends TestCase
{
private Product $product;
protected function setUp(): void
{
// Construct via StdClass path (allocateObject), which requires no DB access.
$obj = new stdClass();
$obj->bnet_product_id = 0x01;
$obj->bnet_product_raw = 'STAR';
$obj->bnls_product_id = 1;
$obj->label = 'StarCraft';
$obj->sort = 0;
$obj->version_byte = 0xCD;
$this->product = new Product($obj);
}
// Getters reflect StdClass construction
public function testGetBnetProductId(): void
{
$this->assertSame(0x01, $this->product->getBnetProductId());
}
public function testGetBnetProductRaw(): void
{
$this->assertSame('STAR', $this->product->getBnetProductRaw());
}
public function testGetBnlsProductId(): void
{
$this->assertSame(1, $this->product->getBnlsProductId());
}
public function testGetLabel(): void
{
$this->assertSame('StarCraft', $this->product->getLabel());
}
public function testGetSort(): void
{
$this->assertSame(0, $this->product->getSort());
}
public function testGetVersionByte(): void
{
$this->assertSame(0xCD, $this->product->getVersionByte());
}
// Setters
public function testSetBnetProductRawChangesValue(): void
{
$this->product->setBnetProductRaw('W2BN');
$this->assertSame('W2BN', $this->product->getBnetProductRaw());
}
public function testSetBnlsProductIdChangesValue(): void
{
$this->product->setBnlsProductId(42);
$this->assertSame(42, $this->product->getBnlsProductId());
}
public function testSetLabelChangesValue(): void
{
$this->product->setLabel('Warcraft II');
$this->assertSame('Warcraft II', $this->product->getLabel());
}
public function testSetSortChangesValue(): void
{
$this->product->setSort(5);
$this->assertSame(5, $this->product->getSort());
}
public function testSetVersionByteChangesValue(): void
{
$this->product->setVersionByte(0xDD);
$this->assertSame(0xDD, $this->product->getVersionByte());
}
// commit() always returns false (read-only product table)
public function testCommitAlwaysReturnsFalse(): void
{
$this->assertFalse($this->product->commit());
}
// jsonSerialize
public function testJsonSerializeHasExpectedKeys(): void
{
$data = $this->product->jsonSerialize();
foreach ([
'bnet_product_id', 'bnet_product_raw', 'bnls_product_id',
'label', 'sort', 'version_byte',
] as $key) {
$this->assertArrayHasKey($key, $data, "Missing key: $key");
}
}
public function testJsonSerializeReflectsConstructedValues(): void
{
$data = $this->product->jsonSerialize();
$this->assertSame(0x01, $data['bnet_product_id']);
$this->assertSame('STAR', $data['bnet_product_raw']);
$this->assertSame(1, $data['bnls_product_id']);
$this->assertSame('StarCraft', $data['label']);
$this->assertSame(0, $data['sort']);
$this->assertSame(0xCD, $data['version_byte']);
}
}