+86
tests/Unit/Data/LexiconDocumentTest.php
+86
tests/Unit/Data/LexiconDocumentTest.php
···
33
$this->assertSame($data, $doc->raw);
34
}
35
36
public function test_it_throws_on_missing_lexicon(): void
37
{
38
$this->expectException(SchemaValidationException::class);
···
150
]);
151
152
$this->assertSame('app.bsky.feed.post', $doc->getNsid());
153
}
154
155
public function test_it_converts_to_array(): void
···
33
$this->assertSame($data, $doc->raw);
34
}
35
36
+
public function test_it_creates_from_json(): void
37
+
{
38
+
$json = json_encode([
39
+
'lexicon' => 1,
40
+
'id' => 'app.bsky.feed.post',
41
+
'description' => 'A post record',
42
+
'defs' => [
43
+
'main' => [
44
+
'type' => 'record',
45
+
],
46
+
],
47
+
]);
48
+
49
+
$doc = LexiconDocument::fromJson($json, 'test.json');
50
+
51
+
$this->assertSame(1, $doc->lexicon);
52
+
$this->assertInstanceOf(Nsid::class, $doc->id);
53
+
$this->assertSame('app.bsky.feed.post', $doc->id->toString());
54
+
$this->assertSame('A post record', $doc->description);
55
+
$this->assertArrayHasKey('main', $doc->defs);
56
+
$this->assertSame('test.json', $doc->source);
57
+
}
58
+
59
+
public function test_it_creates_from_json_without_source(): void
60
+
{
61
+
$json = json_encode([
62
+
'lexicon' => 1,
63
+
'id' => 'app.bsky.feed.post',
64
+
'defs' => [
65
+
'main' => ['type' => 'record'],
66
+
],
67
+
]);
68
+
69
+
$doc = LexiconDocument::fromJson($json);
70
+
71
+
$this->assertSame(1, $doc->lexicon);
72
+
$this->assertSame('app.bsky.feed.post', $doc->id->toString());
73
+
$this->assertNull($doc->source);
74
+
}
75
+
76
+
public function test_it_throws_on_invalid_json(): void
77
+
{
78
+
$this->expectException(\InvalidArgumentException::class);
79
+
$this->expectExceptionMessage('Invalid JSON');
80
+
81
+
LexiconDocument::fromJson('{"invalid json');
82
+
}
83
+
84
+
public function test_it_throws_on_non_array_json(): void
85
+
{
86
+
$this->expectException(\InvalidArgumentException::class);
87
+
$this->expectExceptionMessage('JSON must decode to an array');
88
+
89
+
LexiconDocument::fromJson('"just a string"');
90
+
}
91
+
92
+
public function test_it_throws_on_json_array_list(): void
93
+
{
94
+
$this->expectException(\InvalidArgumentException::class);
95
+
$this->expectExceptionMessage('JSON must decode to an array');
96
+
97
+
LexiconDocument::fromJson('123');
98
+
}
99
+
100
public function test_it_throws_on_missing_lexicon(): void
101
{
102
$this->expectException(SchemaValidationException::class);
···
214
]);
215
216
$this->assertSame('app.bsky.feed.post', $doc->getNsid());
217
+
}
218
+
219
+
public function test_it_gets_version(): void
220
+
{
221
+
$doc = LexiconDocument::fromArray([
222
+
'lexicon' => 1,
223
+
'id' => 'app.bsky.feed.post',
224
+
'defs' => [],
225
+
]);
226
+
227
+
$this->assertSame(1, $doc->getVersion());
228
+
}
229
+
230
+
public function test_it_gets_version_same_as_lexicon_property(): void
231
+
{
232
+
$doc = LexiconDocument::fromArray([
233
+
'lexicon' => 1,
234
+
'id' => 'app.bsky.feed.post',
235
+
'defs' => [],
236
+
]);
237
+
238
+
$this->assertSame($doc->lexicon, $doc->getVersion());
239
}
240
241
public function test_it_converts_to_array(): void