summaryrefslogtreecommitdiffstats
path: root/igbinary-tests.patch
blob: 8df5caa1f769019887f63358dc8d446d190a7bd5 (plain)
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
From: Tyson Andre <tysonandre775@hotmail.com>
Date: Sun, 23 Aug 2020 17:35:38 -0400
Subject: [PATCH] Update tests for php 8.0

Fixes #278
---
 .appveyor.yml                 |  15 +-
 .travis.yml                   |   9 +-
 ci/run-tests-parallel.php     | 486 ++++++++++++++++++++++------------
 package.xml                   |  23 +-
 src/php7/igbinary.h           |   2 +-
 tests/igbinary_009b.phpt      |   3 +
 tests/igbinary_009b_php8.phpt | 114 ++++++++
 tests/igbinary_026.phpt       |   5 +-
 tests/igbinary_026_php8.phpt  | 100 +++++++
 tests/igbinary_026b.phpt      |   3 +
 tests/igbinary_026b_php8.phpt |  86 ++++++
 11 files changed, 663 insertions(+), 183 deletions(-)
 create mode 100644 tests/igbinary_009b_php8.phpt
 create mode 100644 tests/igbinary_026_php8.phpt
 create mode 100644 tests/igbinary_026b_php8.phpt

diff --git a/tests/igbinary_009b.phpt b/tests/igbinary_009b.phpt
index 75fb2be..6322011 100644
--- a/tests/igbinary_009b.phpt
+++ b/tests/igbinary_009b.phpt
@@ -5,6 +5,9 @@ Check for reference serialization (Original example, not using var_dump)
 if (!extension_loaded('igbinary')) {
 	echo "skip no igbinary";
 }
+if (PHP_MAJOR_VERSION > 7) {
+	echo "skip requires php 7.x\n";
+}
 --INI--
 pcre.jit=0
 --FILE--
diff --git a/tests/igbinary_009b_php8.phpt b/tests/igbinary_009b_php8.phpt
new file mode 100644
index 0000000..483576a
--- /dev/null
+++ b/tests/igbinary_009b_php8.phpt
@@ -0,0 +1,114 @@
+--TEST--
+Check for reference serialization in php 8 (Original example, not using var_dump)
+--SKIPIF--
+<?php
+if (!extension_loaded('igbinary')) {
+	echo "skip no igbinary";
+}
+if (PHP_MAJOR_VERSION < 8) {
+	echo "skip requires php 8.0+\n";
+}
+--INI--
+pcre.jit=0
+--FILE--
+<?php
+error_reporting(E_ALL|E_STRICT);
+// Verify that $type[0] is the same zval as $type[0][0][0], but different from $type[0]
+function test_cyclic2($type, $variable) {
+	$serialized = igbinary_serialize($variable);
+	$unserialized = igbinary_unserialize($serialized);
+	echo $type, "\n";
+	echo substr(bin2hex($serialized), 8), "\n";
+	// Can't use === or == on two recursive arrays in some cases
+	echo array_keys($unserialized) === array_keys($variable) && array_keys($unserialized[0]) === array_keys($variable[0]) ? 'OK' : 'ERROR', "\n";
+	ob_start();
+	var_dump($variable);
+	$dump_exp = ob_get_clean();
+	ob_start();
+	var_dump($unserialized);
+	$dump_act = ob_get_clean();
+	if (preg_replace('/&array/', 'array', $dump_act) !== preg_replace('/&array/', 'array', $dump_exp)) {
+		echo "But var dump differs:\nActual:\n", $dump_act, "\nExpected\n", $dump_exp, "\n";
+		echo "(Was normalized)\n";
+	}
+
+	if (!isset($unserialized[0]) || count($unserialized) != 1) {
+		printf("Unexpected keys: %s\n", array_keys($unserialized));
+		return;
+	} else if (!is_array($unserialized)) {
+		printf("\$a[0] is not an array, it is %s", gettype($unserialized));
+		return;
+	}
+	// Set a key, check for the presence of the key 2 levels deeper (Should find it) and 1 level deeper (Should not find it)
+	$unserialized[0]['test'] = 'foo';
+	if ($unserialized[0][0][0]['test'] !== 'foo') {
+		echo "Expected the unserialized array to be cyclic\n";
+	}
+	if (isset($unserialized[0][0]['test'])) {
+		echo "Expected the unserialized array to be cyclic AND of cycle depth 2, but cycle depth is 1\n";
+	}
+}
+$a = [null];
+$b = [&$a];
+$a[0] = &$b;
+// 1401060025140106002514010600250101 could also be serialized as 14010600251401060014010600250101 if we normalized the references which only occurred once in the serialization
+// (Replace middle &array(&$a) with array(&$array), i.e. second 2514 with 14)
+test_cyclic2('cyclic $a = array(&array(&$a)) - testing functionality', $a);
+unset($a);
+$a = null;
+$a = [[&$a]];
+test_cyclic2('cyclic $a = array(array(&$a)); $a[0] - testing functionality', $a[0]);
+// $a serializes as 140106001401060025140106000101 - This is a bug, probably exists in php5 as well.
+--EXPECT--
+cyclic $a = array(&array(&$a)) - testing functionality
+1401060025140106002514010600250101
+OK
+But var dump differs:
+Actual:
+array(1) {
+  [0]=>
+  &array(1) {
+    [0]=>
+    array(1) {
+      [0]=>
+      *RECURSION*
+    }
+  }
+}
+
+Expected
+array(1) {
+  [0]=>
+  &array(1) {
+    [0]=>
+    *RECURSION*
+  }
+}
+
+(Was normalized)
+cyclic $a = array(array(&$a)); $a[0] - testing functionality
+14010600251401060014010600250101
+OK
+But var dump differs:
+Actual:
+array(1) {
+  [0]=>
+  &array(1) {
+    [0]=>
+    array(1) {
+      [0]=>
+      *RECURSION*
+    }
+  }
+}
+
+Expected
+array(1) {
+  [0]=>
+  &array(1) {
+    [0]=>
+    *RECURSION*
+  }
+}
+
+(Was normalized)
\ No newline at end of file
diff --git a/tests/igbinary_026.phpt b/tests/igbinary_026.phpt
index 950a218..c3f4386 100644
--- a/tests/igbinary_026.phpt
+++ b/tests/igbinary_026.phpt
@@ -4,9 +4,12 @@ Cyclic array test
 report_memleaks=0
 --SKIPIF--
 <?php
-if(!extension_loaded('igbinary')) {
+if (!extension_loaded('igbinary')) {
 	echo "skip no igbinary";
 }
+if (PHP_MAJOR_VERSION > 7) {
+	echo "skip requires php 7.x\n";
+}
 --FILE--
 <?php
 
diff --git a/tests/igbinary_026_php8.phpt b/tests/igbinary_026_php8.phpt
new file mode 100644
index 0000000..91313d1
--- /dev/null
+++ b/tests/igbinary_026_php8.phpt
@@ -0,0 +1,100 @@
+--TEST--
+Cyclic array test
+--INI--
+report_memleaks=0
+--SKIPIF--
+<?php
+if (!extension_loaded('igbinary')) {
+	echo "skip no igbinary\n";
+}
+if (PHP_MAJOR_VERSION < 8) {
+	echo "skip requires php 8.0+\n";
+}
+--FILE--
+<?php
+
+function test($type, $variable, $test) {
+	$serialized = igbinary_serialize($variable);
+	$unserialized = igbinary_unserialize($serialized);
+
+	echo $type, "\n";
+	echo substr(bin2hex($serialized), 8), "\n";
+	echo !$test || $unserialized == $variable ? 'OK' : 'ERROR', "\n";
+}
+
+$a = array(
+	'a' => array(
+		'b' => 'c',
+		'd' => 'e'
+	),
+);
+
+$a['f'] = &$a;
+
+test('array', $a, false);
+
+$a = array("foo" => &$b);
+$b = array(1, 2, $a);
+
+$exp = $a;
+$act = igbinary_unserialize(igbinary_serialize($a));
+
+ob_start();
+var_dump($exp);
+$dump_exp = ob_get_clean();
+ob_start();
+var_dump($act);
+$dump_act = ob_get_clean();
+
+if ($dump_act !== $dump_exp) {
+	echo "Var dump differs:\nActual:\n", $dump_act, "\nExpected:\n", $dump_exp, "\n";
+} else {
+	echo "Var dump OK\n";
+}
+
+$act['foo'][1] = 'test value';
+$exp['foo'][1] = 'test value';
+if ($act['foo'][1] !== $act['foo'][2]['foo'][1]) {
+	echo "Recursive elements differ:\n";
+	echo "Actual\n";
+	var_dump($act);
+	var_dump($act['foo']);
+	echo "Expected\n";
+	var_dump($exp);
+	var_dump($exp['foo']);
+}
+
+?>
+--EXPECT--
+array
+140211016114021101621101631101641101651101662514020e0001010e05250102
+OK
+Var dump differs:
+Actual:
+array(1) {
+  ["foo"]=>
+  &array(3) {
+    [0]=>
+    int(1)
+    [1]=>
+    int(2)
+    [2]=>
+    array(1) {
+      ["foo"]=>
+      *RECURSION*
+    }
+  }
+}
+
+Expected:
+array(1) {
+  ["foo"]=>
+  &array(3) {
+    [0]=>
+    int(1)
+    [1]=>
+    int(2)
+    [2]=>
+    *RECURSION*
+  }
+}
diff --git a/tests/igbinary_026b.phpt b/tests/igbinary_026b.phpt
index ba17ae3..6d0ad0d 100644
--- a/tests/igbinary_026b.phpt
+++ b/tests/igbinary_026b.phpt
@@ -7,6 +7,9 @@ report_memleaks=0
 if (!extension_loaded('igbinary')) {
 	echo "skip no igbinary";
 }
+if (PHP_MAJOR_VERSION > 7) {
+	echo "skip requires php 7.x\n";
+}
 --FILE--
 <?php
 
diff --git a/tests/igbinary_026b_php8.phpt b/tests/igbinary_026b_php8.phpt
new file mode 100644
index 0000000..b5ffa9c
--- /dev/null
+++ b/tests/igbinary_026b_php8.phpt
@@ -0,0 +1,86 @@
+--TEST--
+Cyclic array test 2
+--INI--
+report_memleaks=0
+--SKIPIF--
+<?php
+if (!extension_loaded('igbinary')) {
+	echo "skip no igbinary\n";
+}
+if (PHP_MAJOR_VERSION < 8) {
+	echo "skip requires php 8\n";
+}
+--FILE--
+<?php
+
+$a = array("foo" => &$b);
+$b = array(1, 2, $a);
+
+/* all three statements below should produce same output however PHP stock
+ * unserialize/serialize produces different output (5.2.16). I consider this is
+ * a PHP bug. - Oleg Grenrus
+ */
+
+/* NOTE: This is different in php 8 because igbinary_unserialize() is declared to return a reference, not a value */
+
+//$k = $a;
+//$k = unserialize(serialize($a));
+$k = igbinary_unserialize(igbinary_serialize($a));
+
+function check($a, $k) {
+	ob_start();
+	var_dump($a);
+	$a_str = ob_get_clean();
+	ob_start();
+	var_dump($k);
+	$k_str = ob_get_clean();
+
+	if ($a_str !== $k_str) {
+		echo "Output differs\n";
+		echo "Expected:\n", $a_str, "\n";
+		echo "Actual:\n", $k_str, "\n";
+	} else {
+		echo "OK\n";
+	}
+}
+
+check($a, $k);
+
+$a["foo"][2]["foo"][1] = "b";
+$k["foo"][2]["foo"][1] = "b";
+
+check($a, $k);
+
+?>
+--EXPECT--
+Output differs
+Expected:
+array(1) {
+  ["foo"]=>
+  &array(3) {
+    [0]=>
+    int(1)
+    [1]=>
+    int(2)
+    [2]=>
+    *RECURSION*
+  }
+}
+
+Actual:
+array(1) {
+  ["foo"]=>
+  &array(3) {
+    [0]=>
+    int(1)
+    [1]=>
+    int(2)
+    [2]=>
+    array(1) {
+      ["foo"]=>
+      *RECURSION*
+    }
+  }
+}
+
+OK
\ No newline at end of file