1--TEST-- 2disabled php only for class methods (set option) 3--SKIPIF-- 4--FILE-- 5<?php 6if(!extension_loaded('msgpack')) { 7 dl('msgpack.' . PHP_SHLIB_SUFFIX); 8} 9 10function test($type, $variable, $test = null) { 11 $msgpack = new MessagePack(); 12 if (version_compare(PHP_VERSION, '5.1.0') < 0) 13 { 14 $msgpack->setOption(MESSAGEPACK_OPT_PHPONLY, false); 15 } 16 else 17 { 18 $msgpack->setOption(MessagePack::OPT_PHPONLY, false); 19 } 20 21 $serialized = $msgpack->pack($variable); 22 $unserialized = $msgpack->unpack($serialized); 23 24 var_dump($unserialized); 25 26 if (!is_bool($test)) 27 { 28 echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL; 29 } 30 else 31 { 32 echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL; 33 } 34} 35 36test('null', null); 37 38test('bool: true', true); 39test('bool: false', false); 40 41test('zero: 0', 0); 42test('small: 1', 1); 43test('small: -1', -1); 44test('medium: 1000', 1000); 45test('medium: -1000', -1000); 46test('large: 100000', 100000); 47test('large: -100000', -100000); 48 49test('double: 123.456', 123.456); 50 51test('empty: ""', ""); 52test('string: "foobar"', "foobar"); 53 54test('array: empty', array(), false); 55test('array(1, 2, 3)', array(1, 2, 3), false); 56test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); 57 58test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); 59test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); 60test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); 61test('array("" => "empty")', array("" => "empty"), false); 62 63$a = array('foo'); 64test('array($a, $a)', array($a, $a), false); 65test('array(&$a, &$a)', array(&$a, &$a), false); 66 67$a = array(null); 68$b = array(&$a); 69$a[0] = &$b; 70 71test('cyclic', $a, true); 72 73$a = array( 74 'a' => array( 75 'b' => 'c', 76 'd' => 'e' 77 ), 78 'f' => array( 79 'g' => 'h' 80 ) 81 ); 82 83test('array', $a, false); 84 85class Obj { 86 public $a; 87 protected $b; 88 private $c; 89 90 function __construct($a, $b, $c) { 91 $this->a = $a; 92 $this->b = $b; 93 $this->c = $c; 94 } 95} 96 97test('object', new Obj(1, 2, 3), true); 98 99test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), true); 100 101$o = new Obj(1, 2, 3); 102 103test('object', array(&$o, &$o), true); 104--EXPECTF-- 105NULL 106OK 107bool(true) 108OK 109bool(false) 110OK 111int(0) 112OK 113int(1) 114OK 115int(-1) 116OK 117int(1000) 118OK 119int(-1000) 120OK 121int(100000) 122OK 123int(-100000) 124OK 125float(123.456) 126OK 127string(0) "" 128OK 129string(6) "foobar" 130OK 131array(0) { 132} 133OK 134array(3) { 135 [0]=> 136 int(1) 137 [1]=> 138 int(2) 139 [2]=> 140 int(3) 141} 142OK 143array(3) { 144 [0]=> 145 array(3) { 146 [0]=> 147 int(1) 148 [1]=> 149 int(2) 150 [2]=> 151 int(3) 152 } 153 [1]=> 154 array(3) { 155 [0]=> 156 int(4) 157 [1]=> 158 int(5) 159 [2]=> 160 int(6) 161 } 162 [2]=> 163 array(3) { 164 [0]=> 165 int(7) 166 [1]=> 167 int(8) 168 [2]=> 169 int(9) 170 } 171} 172OK 173array(3) { 174 [0]=> 175 string(3) "foo" 176 [1]=> 177 string(3) "foo" 178 [2]=> 179 string(3) "foo" 180} 181OK 182array(2) { 183 ["one"]=> 184 int(1) 185 ["two"]=> 186 int(2) 187} 188OK 189array(2) { 190 ["kek"]=> 191 string(3) "lol" 192 ["lol"]=> 193 string(3) "kek" 194} 195OK 196array(1) { 197 [""]=> 198 string(5) "empty" 199} 200OK 201array(2) { 202 [0]=> 203 array(1) { 204 [0]=> 205 string(3) "foo" 206 } 207 [1]=> 208 array(1) { 209 [0]=> 210 string(3) "foo" 211 } 212} 213OK 214array(2) { 215 [0]=> 216 array(1) { 217 [0]=> 218 string(3) "foo" 219 } 220 [1]=> 221 array(1) { 222 [0]=> 223 string(3) "foo" 224 } 225} 226OK 227array(1) { 228 [0]=> 229 array(1) { 230 [0]=> 231 array(1) { 232 [0]=> 233 NULL 234 } 235 } 236} 237OK 238array(2) { 239 ["a"]=> 240 array(2) { 241 ["b"]=> 242 string(1) "c" 243 ["d"]=> 244 string(1) "e" 245 } 246 ["f"]=> 247 array(1) { 248 ["g"]=> 249 string(1) "h" 250 } 251} 252OK 253array(3) { 254 [0]=> 255 int(1) 256 [1]=> 257 int(2) 258 [2]=> 259 int(3) 260} 261OK 262array(2) { 263 [0]=> 264 array(3) { 265 [0]=> 266 int(1) 267 [1]=> 268 int(2) 269 [2]=> 270 int(3) 271 } 272 [1]=> 273 array(3) { 274 [0]=> 275 int(4) 276 [1]=> 277 int(5) 278 [2]=> 279 int(6) 280 } 281} 282OK 283array(2) { 284 [0]=> 285 array(3) { 286 [0]=> 287 int(1) 288 [1]=> 289 int(2) 290 [2]=> 291 int(3) 292 } 293 [1]=> 294 array(3) { 295 [0]=> 296 int(1) 297 [1]=> 298 int(2) 299 [2]=> 300 int(3) 301 } 302} 303OK 304