Skip to content

Commit 9282bce

Browse files
committed
feat: add serialization and parsing tests for resources and non-array values
1 parent 5aee398 commit 9282bce

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

tests/Unit/Support/JavaScriptSerializerTest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@
214214
});
215215

216216
it('serializes big integers correctly', function (): void {
217-
$bigInt = 9007199254740993;
217+
$bigInt = 9007199254740993; // Greater than JavaScript's MAX_SAFE_INTEGER
218218
$result = JavaScriptSerializer::serializeValue($bigInt);
219219

220220
expect($result)->toHaveKey('bi');
@@ -227,3 +227,21 @@
227227

228228
expect($result)->toBe('9007199254740993');
229229
});
230+
231+
it('serializes resources as strings (fallback)', function (): void {
232+
$resource = fopen('php://memory', 'r');
233+
$result = JavaScriptSerializer::serializeValue($resource);
234+
235+
expect($result)->toHaveKey('s');
236+
expect($result['s'])->toBeString();
237+
expect($result['s'])->toContain('Resource');
238+
239+
fclose($resource);
240+
});
241+
242+
it('parses values that are not arrays as-is', function (): void {
243+
expect(JavaScriptSerializer::parseValue('plain string'))->toBe('plain string');
244+
expect(JavaScriptSerializer::parseValue(42))->toBe(42);
245+
expect(JavaScriptSerializer::parseValue(true))->toBeTrue();
246+
expect(JavaScriptSerializer::parseValue(null))->toBeNull();
247+
});

0 commit comments

Comments
 (0)