summaryrefslogtreecommitdiff
path: root/ext/json/tests
diff options
context:
space:
mode:
authorJakub Zelenka <bukka@php.net>2016-10-30 13:20:10 +0000
committerJakub Zelenka <bukka@php.net>2016-10-30 13:20:10 +0000
commitc34de0b61c68bd77e324b869760a53abead4c5ed (patch)
tree54dc1cb22510d6c992e47f9fef7a78e1290fa85e /ext/json/tests
parentbe6bf71274a4670d7c7f45142890eb0651359c64 (diff)
downloadphp-git-c34de0b61c68bd77e324b869760a53abead4c5ed.tar.gz
Introduce json encoder to fix globals related issues
It fixes bugs #66025 and #73254 by replacing globals with a passed structure holding depth and error code. In addition it fixes #72069 in a more generic way.
Diffstat (limited to 'ext/json/tests')
-rw-r--r--ext/json/tests/bug66025.phpt19
-rw-r--r--ext/json/tests/bug73254.phpt21
2 files changed, 40 insertions, 0 deletions
diff --git a/ext/json/tests/bug66025.phpt b/ext/json/tests/bug66025.phpt
new file mode 100644
index 0000000000..9322d39b66
--- /dev/null
+++ b/ext/json/tests/bug66025.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Bug #66025 (Indent wrong when json_encode() called from jsonSerialize function)
+--SKIPIF--
+<?php
+if (!extension_loaded('json')) die('skip');
+?>
+--FILE--
+<?php
+
+class Foo implements JsonSerializable {
+ public function jsonSerialize() {
+ return json_encode([1], JSON_PRETTY_PRINT);
+ }
+}
+
+echo json_encode([new Foo]), "\n";
+?>
+--EXPECT--
+["[\n 1\n]"]
diff --git a/ext/json/tests/bug73254.phpt b/ext/json/tests/bug73254.phpt
new file mode 100644
index 0000000000..b043330cb7
--- /dev/null
+++ b/ext/json/tests/bug73254.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Bug #73254 (Incorrect indentation generated by json_encode() with JSON_PRETTY_PRINT)
+--SKIPIF--
+<?php
+if (!extension_loaded('json')) die('skip');
+?>
+--FILE--
+<?php
+
+echo json_encode([json_encode([1], JSON_PRETTY_PRINT)]), "\n";
+
+$fp = fopen('php://temp', 'r');
+$data = ['a' => $fp];
+echo json_encode($data), "\n";
+echo json_encode([json_encode([1], JSON_PRETTY_PRINT)]), "\n";
+
+?>
+--EXPECT--
+["[\n 1\n]"]
+
+["[\n 1\n]"]