Skip to content

Commit 2eb2f41

Browse files
committed
separate serializable and magic serialize test
1 parent 7e4f756 commit 2eb2f41

File tree

2 files changed

+66
-9
lines changed

2 files changed

+66
-9
lines changed

tests/021.phpt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Object Serializable interface
33
--SKIPIF--
44
<?php
5-
if (version_compare(PHP_VERSION, '5.1.0') < 0) {
6-
echo "skip tests in PHP 5.1 or newer";
5+
if (version_compare(PHP_VERSION, '5.1.0') < 0 || version_compare(PHP_VERSION, '8.1.0dev') >= 0) {
6+
echo "skip tests in PHP 5.1-8.1";
77
}
88
--FILE--
99
<?php
@@ -39,13 +39,6 @@ class Obj implements Serializable {
3939
$this->__construct($tmp[1], $tmp[2]);
4040
}
4141

42-
public function __serialize() {
43-
return [$this->serialize()];
44-
}
45-
46-
public function __unserialize($serialized) {
47-
return $this->unserialize($serialized[0]);
48-
}
4942
}
5043

5144
$o = new Obj(1, 2);

tests/021a.phpt

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
--TEST--
2+
Object Serializable interface
3+
--SKIPIF--
4+
<?php
5+
if (version_compare(PHP_VERSION, '8.1.0dev') < 0) {
6+
echo "skip tests in PHP 8.1+";
7+
}
8+
--FILE--
9+
<?php
10+
if(!extension_loaded('msgpack')) {
11+
dl('msgpack.' . PHP_SHLIB_SUFFIX);
12+
}
13+
14+
function test($type, $variable, $test) {
15+
$serialized = msgpack_serialize($variable);
16+
$unserialized = msgpack_unserialize($serialized);
17+
18+
echo $type, PHP_EOL;
19+
echo bin2hex($serialized), PHP_EOL;
20+
var_dump($unserialized);
21+
echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL;
22+
}
23+
24+
class Obj implements Serializable {
25+
var $a;
26+
var $b;
27+
28+
function __construct($a, $b) {
29+
$this->a = $a;
30+
$this->b = $b;
31+
}
32+
33+
public function serialize() {
34+
return pack('NN', $this->a, $this->b);
35+
}
36+
37+
public function unserialize($serialized) {
38+
$tmp = unpack('N*', $serialized);
39+
$this->__construct($tmp[1], $tmp[2]);
40+
}
41+
42+
public function __serialize() {
43+
return [$this->serialize()];
44+
}
45+
46+
public function __unserialize($serialized) {
47+
return $this->unserialize($serialized[0]);
48+
}
49+
}
50+
51+
$o = new Obj(1, 2);
52+
53+
test('object', $o, false);
54+
?>
55+
--EXPECTF--
56+
object
57+
82c0a34f626ac091a80000000100000002
58+
object(Obj)#%d (2) {
59+
["a"]=>
60+
int(1)
61+
["b"]=>
62+
int(2)
63+
}
64+
OK

0 commit comments

Comments
 (0)