test(json): add test case for JSON exception boundary behavior

- Verify json_decode with JSON_THROW_ON_ERROR throws JsonException on invalid input
- Confirm json_encode with recursive structure throws JsonException when using JSON_THROW_ON_ERROR
- Test json
pull/48/head
韩天峰 2 weeks ago
parent 0ba5079336
commit 3b51eaa6d0
  1. 50
      tests/compiler/basic/json-exception-boundary.phpt

@ -0,0 +1,50 @@
--TEST--
JSON optimized functions preserve PHP exceptions and option semantics
--FILE--
<?php
function main(): void
{
try {
json_decode('{broken', true, 512, JSON_THROW_ON_ERROR);
echo "decode-not-caught\n";
} catch (JsonException $exception) {
echo "decode-caught\n";
}
$recursive = [];
$recursive['self'] = &$recursive;
try {
json_encode($recursive, JSON_THROW_ON_ERROR);
echo "encode-not-caught\n";
} catch (JsonException $exception) {
echo "encode-caught\n";
}
var_dump(json_decode('{broken') === null);
var_dump(json_last_error() === JSON_ERROR_SYNTAX);
var_dump(json_decode('{"value":1}') instanceof stdClass);
var_dump(json_last_error() === JSON_ERROR_NONE);
$object = json_decode('{"value":1}', false, 512, JSON_OBJECT_AS_ARRAY);
var_dump($object instanceof stdClass);
try {
json_decode('{}', true, 0);
echo "depth-not-caught\n";
} catch (ValueError $exception) {
echo "depth-caught\n";
}
}
?>
--EXPECT--
decode-caught
encode-caught
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
depth-caught
Loading…
Cancel
Save