1<?php 2require_once('CouchbaseTestCase.php'); 3 4class TranscoderTest extends CouchbaseTestCase { 5 function testPassthruEncoder() { 6 $res = \Couchbase\passthruEncoder("foobar"); 7 $this->assertEquals(["foobar", 0, 0], $res); 8 9 $res = \Couchbase\passthruEncoder('{"foo": 1}'); 10 $this->assertEquals(['{"foo": 1}', 0, 0], $res); 11 12 $res = \Couchbase\passthruEncoder(NULL); 13 $this->assertEquals([NULL, 0, 0], $res); 14 } 15 16 function testPassthruDecoder() { 17 $res = \Couchbase\passthruDecoder("foobar", 0, 0); 18 $this->assertEquals("foobar", $res); 19 20 $res = \Couchbase\passthruDecoder("foobar", 0xdeadbeef, 42); 21 $this->assertEquals("foobar", $res); 22 23 $res = \Couchbase\passthruDecoder(["foo" => 1], 0, 0); 24 $this->assertEquals(["foo" => 1], $res); 25 26 $res = \Couchbase\passthruDecoder(NULL, 0, 0); 27 $this->assertEquals(NULL, $res); 28 } 29 30 /** 31 * For Common Flags encoding see RFC-20 at 32 * https://github.com/couchbaselabs/sdk-rfcs 33 */ 34 function testCouchbaseBasicEncoderV1() { 35 $options = array( 36 'sertype' => COUCHBASE_SERTYPE_JSON, 37 'cmprtype' => COUCHBASE_CMPRTYPE_NONE, 38 'cmprthresh' => 0, 39 'cmprfactor' => 0 40 ); 41 42 $res = \Couchbase\basicEncoderV1("foo", $options); 43 $this->assertEquals(COUCHBASE_COMPRESSION_NONE, $res[1] & COUCHBASE_COMPRESSION_MASK); 44 $this->assertEquals(COUCHBASE_CFFMT_STRING, $res[1] & COUCHBASE_CFFMT_MASK); 45 $this->assertEquals(COUCHBASE_VAL_IS_STRING, $res[1] & COUCHBASE_VAL_MASK); 46 $this->assertEquals(["foo", 0x04000000, 0], $res); 47 48 $res = \Couchbase\basicEncoderV1(1, $options); 49 $this->assertEquals(COUCHBASE_COMPRESSION_NONE, $res[1] & COUCHBASE_COMPRESSION_MASK); 50 $this->assertEquals(COUCHBASE_CFFMT_JSON, $res[1] & COUCHBASE_CFFMT_MASK); 51 $this->assertEquals(COUCHBASE_VAL_IS_LONG, $res[1] & COUCHBASE_VAL_MASK); 52 $this->assertEquals(["1", 0x02000001, 0], $res); 53 54 $res = \Couchbase\basicEncoderV1(0xabcdef0123456789, $options); 55 $this->assertEquals(COUCHBASE_COMPRESSION_NONE, $res[1] & COUCHBASE_COMPRESSION_MASK); 56 $this->assertEquals(COUCHBASE_CFFMT_JSON, $res[1] & COUCHBASE_CFFMT_MASK); 57 $this->assertEquals(COUCHBASE_VAL_IS_DOUBLE, $res[1] & COUCHBASE_VAL_MASK); 58 $this->assertEquals(["1.2379813738877E+19", 0x02000002, 0], $res); 59 60 $res = \Couchbase\basicEncoderV1(1.0, $options); 61 $this->assertEquals(COUCHBASE_COMPRESSION_NONE, $res[1] & COUCHBASE_COMPRESSION_MASK); 62 $this->assertEquals(COUCHBASE_CFFMT_JSON, $res[1] & COUCHBASE_CFFMT_MASK); 63 $this->assertEquals(COUCHBASE_VAL_IS_DOUBLE, $res[1] & COUCHBASE_VAL_MASK); 64 $this->assertEquals(["1.0", 0x02000002, 0], $res); 65 66 $res = \Couchbase\basicEncoderV1(true, $options); 67 $this->assertEquals(COUCHBASE_COMPRESSION_NONE, $res[1] & COUCHBASE_COMPRESSION_MASK); 68 $this->assertEquals(COUCHBASE_CFFMT_JSON, $res[1] & COUCHBASE_CFFMT_MASK); 69 $this->assertEquals(COUCHBASE_VAL_IS_BOOL, $res[1] & COUCHBASE_VAL_MASK); 70 $this->assertEquals(["true", 0x02000003, 0], $res); 71 72 $res = \Couchbase\basicEncoderV1(["foo" => 0xabcdef0123456789], $options); 73 $this->assertEquals(COUCHBASE_COMPRESSION_NONE, $res[1] & COUCHBASE_COMPRESSION_MASK); 74 $this->assertEquals(COUCHBASE_CFFMT_JSON, $res[1] & COUCHBASE_CFFMT_MASK); 75 $this->assertEquals(COUCHBASE_VAL_IS_JSON, $res[1] & COUCHBASE_VAL_MASK); 76 if (phpversion() >= 7.1) { 77 $this->assertEquals(['{"foo":1.2379813738877118e+19}', 0x02000006, 0], $res); 78 } else { 79 $this->assertEquals(['{"foo":1.2379813738877e+19}', 0x02000006, 0], $res); 80 } 81 82 $res = \Couchbase\basicEncoderV1([1, 2, 3], $options); 83 $this->assertEquals(COUCHBASE_COMPRESSION_NONE, $res[1] & COUCHBASE_COMPRESSION_MASK); 84 $this->assertEquals(COUCHBASE_CFFMT_JSON, $res[1] & COUCHBASE_CFFMT_MASK); 85 $this->assertEquals(COUCHBASE_VAL_IS_JSON, $res[1] & COUCHBASE_VAL_MASK); 86 $this->assertEquals(['[1,2,3]', 0x02000006, 0], $res); 87 88 $res = \Couchbase\basicEncoderV1([], $options); 89 $this->assertEquals(COUCHBASE_COMPRESSION_NONE, $res[1] & COUCHBASE_COMPRESSION_MASK); 90 $this->assertEquals(COUCHBASE_CFFMT_JSON, $res[1] & COUCHBASE_CFFMT_MASK); 91 $this->assertEquals(COUCHBASE_VAL_IS_JSON, $res[1] & COUCHBASE_VAL_MASK); 92 $this->assertEquals(['[]', 0x02000006, 0], $res); 93 94 $res = \Couchbase\basicEncoderV1((object)[], $options); 95 $this->assertEquals(COUCHBASE_COMPRESSION_NONE, $res[1] & COUCHBASE_COMPRESSION_MASK); 96 $this->assertEquals(COUCHBASE_CFFMT_JSON, $res[1] & COUCHBASE_CFFMT_MASK); 97 $this->assertEquals(COUCHBASE_VAL_IS_JSON, $res[1] & COUCHBASE_VAL_MASK); 98 $this->assertEquals(['{}', 0x02000006, 0], $res); 99 100 $options['sertype'] = COUCHBASE_SERTYPE_PHP; 101 $res = \Couchbase\basicEncoderV1(["foo" => 0xabcdef0123456789], $options); 102 $this->assertEquals(COUCHBASE_COMPRESSION_NONE, $res[1] & COUCHBASE_COMPRESSION_MASK); 103 $this->assertEquals(COUCHBASE_CFFMT_PRIVATE, $res[1] & COUCHBASE_CFFMT_MASK); 104 $this->assertEquals(COUCHBASE_VAL_IS_SERIALIZED, $res[1] & COUCHBASE_VAL_MASK); 105 $this->assertEquals(['a:1:{s:3:"foo";d:1.2379813738877118E+19;}', 0x01000004, 0], $res); 106 107 // serializer type does not affect serialization of the primitives. 108 // they are always JSON-like strings 109 $res = \Couchbase\basicEncoderV1("foo", $options); 110 $this->assertEquals(COUCHBASE_COMPRESSION_NONE, $res[1] & COUCHBASE_COMPRESSION_MASK); 111 $this->assertEquals(COUCHBASE_CFFMT_STRING, $res[1] & COUCHBASE_CFFMT_MASK); 112 $this->assertEquals(COUCHBASE_VAL_IS_STRING, $res[1] & COUCHBASE_VAL_MASK); 113 $this->assertEquals(["foo", 0x04000000, 0], $res); 114 115 $res = \Couchbase\basicEncoderV1(1.0, $options); 116 $this->assertEquals(COUCHBASE_COMPRESSION_NONE, $res[1] & COUCHBASE_COMPRESSION_MASK); 117 $this->assertEquals(COUCHBASE_CFFMT_JSON, $res[1] & COUCHBASE_CFFMT_MASK); 118 $this->assertEquals(COUCHBASE_VAL_IS_DOUBLE, $res[1] & COUCHBASE_VAL_MASK); 119 $this->assertEquals(["1.0", 0x02000002, 0], $res); 120 121 if (\Couchbase\HAVE_IGBINARY) { 122 $options['sertype'] = COUCHBASE_SERTYPE_IGBINARY; 123 $res = \Couchbase\basicEncoderV1(["foo" => 0xabcdef0123456789], $options); 124 $this->assertEquals(COUCHBASE_COMPRESSION_NONE, $res[1] & COUCHBASE_COMPRESSION_MASK); 125 $this->assertEquals(COUCHBASE_CFFMT_PRIVATE, $res[1] & COUCHBASE_CFFMT_MASK); 126 $this->assertEquals(COUCHBASE_VAL_IS_IGBINARY, $res[1] & COUCHBASE_VAL_MASK); 127 $this->assertEquals([hex2bin("0000000214011103666f6f0c43e579bde02468ad"), 0x01000005, 0], $res); 128 } 129 130 $options['sertype'] = COUCHBASE_SERTYPE_JSON; 131 if (\Couchbase\HAVE_ZLIB) { 132 $options['cmprtype'] = COUCHBASE_CMPRTYPE_ZLIB; 133 134 $options['cmprthresh'] = 40; 135 136 $res = \Couchbase\basicEncoderV1(["foo" => 0xabcdef0123456789], $options); 137 $this->assertEquals(COUCHBASE_COMPRESSION_NONE, $res[1] & COUCHBASE_COMPRESSION_MASK); 138 $this->assertEquals(COUCHBASE_CFFMT_JSON, $res[1] & COUCHBASE_CFFMT_MASK); 139 $this->assertEquals(COUCHBASE_VAL_IS_JSON, $res[1] & COUCHBASE_VAL_MASK); 140 if (phpversion() >= 7.1) { 141 $this->assertEquals(30, strlen($res[0])); 142 $this->assertEquals(['{"foo":1.2379813738877118e+19}', 0x02000006, 0], $res); 143 } else { 144 $this->assertEquals(27, strlen($res[0])); 145 $this->assertEquals(['{"foo":1.2379813738877e+19}', 0x02000006, 0], $res); 146 } 147 148 $options['cmprthresh'] = 20; 149 150 $res = \Couchbase\basicEncoderV1(["foo" => 0xabcdef0123456789], $options); 151 $this->assertEquals(COUCHBASE_COMPRESSION_ZLIB, $res[1] & COUCHBASE_COMPRESSION_MASK); 152 $this->assertEquals(COUCHBASE_COMPRESSION_MCISCOMPRESSED, $res[1] & COUCHBASE_COMPRESSION_MCISCOMPRESSED); 153 $this->assertEquals(COUCHBASE_CFFMT_PRIVATE, $res[1] & COUCHBASE_CFFMT_MASK); 154 $this->assertEquals(COUCHBASE_VAL_IS_JSON | COUCHBASE_COMPRESSION_MCISCOMPRESSED, $res[1] & COUCHBASE_VAL_MASK); 155 $this->assertEquals(COUCHBASE_VAL_IS_JSON, ($res[1] & ~COUCHBASE_COMPRESSION_MCISCOMPRESSED) & COUCHBASE_VAL_MASK); 156 if (phpversion() >= 7.1) { 157 $this->assertEquals(42, strlen($res[0])); 158 $this->assertEquals([hex2bin('1e000000789cab564acbcf57b232d4333236b7b430343637b6b030373734b448d536b4ac050076a00767'), 0x01000036, 0], $res); 159 } else { 160 $this->assertEquals(39, strlen($res[0])); 161 $this->assertEquals([hex2bin('1b000000789cab564acbcf57b232d4333236b7b430343637b6b030374fd536b4ac0500626f06cd'), 0x01000036, 0], $res); 162 } 163 164 $res = \Couchbase\basicEncoderV1('{"foo": 12379813738877118345}', $options); 165 $this->assertEquals(COUCHBASE_COMPRESSION_ZLIB, $res[1] & COUCHBASE_COMPRESSION_MASK); 166 $this->assertEquals(COUCHBASE_COMPRESSION_MCISCOMPRESSED, $res[1] & COUCHBASE_COMPRESSION_MCISCOMPRESSED); 167 $this->assertEquals(COUCHBASE_CFFMT_PRIVATE, $res[1] & COUCHBASE_CFFMT_MASK); 168 $this->assertEquals(COUCHBASE_VAL_IS_STRING | COUCHBASE_COMPRESSION_MCISCOMPRESSED, $res[1] & COUCHBASE_VAL_MASK); 169 $this->assertEquals(COUCHBASE_VAL_IS_STRING, ($res[1] & ~COUCHBASE_COMPRESSION_MCISCOMPRESSED) & COUCHBASE_VAL_MASK); 170 $this->assertEquals(41, strlen($res[0])); 171 $this->assertEquals([hex2bin('1d000000789cab564acbcf57b25230343236b7b430343637b6b030373734b4303631ad05006da106fb'), 0x01000030, 0], $res); 172 } 173 174 $options['cmprtype'] = COUCHBASE_CMPRTYPE_FASTLZ; 175 $options['cmprthresh'] = 40; 176 177 $res = \Couchbase\basicEncoderV1(["foo" => 0xabcdef0123456789], $options); 178 $this->assertEquals(COUCHBASE_COMPRESSION_NONE, $res[1] & COUCHBASE_COMPRESSION_MASK); 179 $this->assertEquals(COUCHBASE_CFFMT_JSON, $res[1] & COUCHBASE_CFFMT_MASK); 180 $this->assertEquals(COUCHBASE_VAL_IS_JSON, $res[1] & COUCHBASE_VAL_MASK); 181 if (phpversion() >= 7.1) { 182 $this->assertEquals(30, strlen($res[0])); 183 $this->assertEquals(['{"foo":1.2379813738877118e+19}', 0x02000006, 0], $res); 184 } else { 185 $this->assertEquals(27, strlen($res[0])); 186 $this->assertEquals(['{"foo":1.2379813738877e+19}', 0x02000006, 0], $res); 187 } 188 189 $options['cmprthresh'] = 20; 190 191 $res = \Couchbase\basicEncoderV1(["foo" => 0xabcdef0123456789], $options); 192 $this->assertEquals(COUCHBASE_COMPRESSION_FASTLZ, $res[1] & COUCHBASE_COMPRESSION_MASK); 193 $this->assertEquals(COUCHBASE_COMPRESSION_MCISCOMPRESSED, $res[1] & COUCHBASE_COMPRESSION_MCISCOMPRESSED); 194 $this->assertEquals(COUCHBASE_CFFMT_PRIVATE, $res[1] & COUCHBASE_CFFMT_MASK); 195 $this->assertEquals(COUCHBASE_VAL_IS_JSON | COUCHBASE_COMPRESSION_MCISCOMPRESSED, $res[1] & COUCHBASE_VAL_MASK); 196 $this->assertEquals(COUCHBASE_VAL_IS_JSON, ($res[1] & ~COUCHBASE_COMPRESSION_MCISCOMPRESSED) & COUCHBASE_VAL_MASK); 197 if (phpversion() >= 7.1) { 198 $this->assertEquals(35, strlen($res[0])); 199 $this->assertEquals([hex2bin('1e0000001d7b22666f6f223a312e32333739383133373338383737313138652b31397d'), 0x01000056, 0], $res); 200 } else { 201 $this->assertEquals(32, strlen($res[0])); 202 $this->assertEquals([hex2bin('1b0000001a7b22666f6f223a312e32333739383133373338383737652b31397d'), 0x01000056, 0], $res); 203 } 204 205 $options['cmprfactor'] = 1.0; // it should be at least 1 byte less than source 206 $res = \Couchbase\basicEncoderV1(["foo" => 0xabcdef0123456789], $options); // 27 < 32 * 1.0 207 $this->assertEquals(COUCHBASE_COMPRESSION_NONE, $res[1] & COUCHBASE_COMPRESSION_MASK); 208 $this->assertEquals(COUCHBASE_CFFMT_JSON, $res[1] & COUCHBASE_CFFMT_MASK); 209 $this->assertEquals(COUCHBASE_VAL_IS_JSON, $res[1] & COUCHBASE_VAL_MASK); 210 if (phpversion() >= 7.1) { 211 $this->assertEquals(30, strlen($res[0])); 212 $this->assertEquals(['{"foo":1.2379813738877118e+19}', 0x02000006, 0], $res); 213 } else { 214 $this->assertEquals(27, strlen($res[0])); 215 $this->assertEquals(['{"foo":1.2379813738877e+19}', 0x02000006, 0], $res); 216 } 217 } 218 219 function testCouchbaseBasicDecoderV1() { 220 $options = [ 221 'jsonassoc' => false 222 ]; 223 224 $res = \Couchbase\basicDecoderV1("foo", 0x04000000, 0, $options); 225 $this->assertEquals("foo", $res); 226 227 $res = \Couchbase\basicDecoderV1("1", 0x02000001, 0, $options); 228 $this->assertEquals(1, $res); 229 230 $original = 0xabcdef0123456789; 231 232 $encoder_options = [ 233 'sertype' => COUCHBASE_SERTYPE_JSON, 234 'cmprtype' => COUCHBASE_CMPRTYPE_NONE, 235 'cmprthresh' => 0, 236 'cmprfactor' => 0 237 ]; 238 $res = \Couchbase\basicEncoderV1($original, $encoder_options); 239 $serialized = $res[0]; 240 $this->assertEquals("1.2379813738877E+19", $serialized); 241 $deserialized = \Couchbase\basicDecoderV1($serialized, 0x02000002, 0, $options); 242 $this->assertNotEquals($deserialized, $original); 243 $this->assertEquals(0xabcdef0123439800, $deserialized); 244 245 $res = \Couchbase\basicDecoderV1("1.0", 0x02000002, 0, $options); 246 $this->assertEquals(1.0, $res); 247 248 $res = \Couchbase\basicDecoderV1("true", 0x02000003, 0, $options); 249 $this->assertEquals(true, $res); 250 251 $res = \Couchbase\basicDecoderV1('{"foo":1.2379813738877e+19}', 0x02000006, 0, $options); 252 $this->assertEquals((object)["foo" => 0xabcdef0123439800], $res); 253 254 // decodes strings from PHP7 as well 255 $res = \Couchbase\basicDecoderV1('{"foo":1.2379813738877118e+19}', 0x02000006, 0, $options); 256 $this->assertEquals((object)["foo" => 0xabcdef0123456789], $res); 257 258 // legacy JSON document with zero flags should be detected 259 $res = \Couchbase\basicDecoderV1('{"foo":1.2379813738877e+19}', 0x0000000, 0, $options); 260 $this->assertEquals((object)["foo" => 0xabcdef0123439800], $res); 261 262 $res = \Couchbase\basicDecoderV1('{"foo":1.2379813738877e+19', 0x0000000, 0, $options); 263 $this->assertEquals('{"foo":1.2379813738877e+19', $res); 264 265 $res = \Couchbase\basicDecoderV1('[1,2,3]', 0x02000006, 0, $options); 266 $this->assertEquals([1, 2, 3], $res); 267 268 $res = \Couchbase\basicDecoderV1('[]', 0x02000006, 0, $options); 269 $this->assertEquals([], $res); 270 271 $res = \Couchbase\basicDecoderV1('{}', 0x02000006, 0, $options); 272 $this->assertEquals((object)[], $res); 273 274 $options['jsonassoc'] = true; 275 $res = \Couchbase\basicDecoderV1('{"foo":1.2379813738877e+19}', 0x02000006, 0, $options); 276 $this->assertEquals(["foo" => 0xabcdef0123439800], $res); 277 278 $res = \Couchbase\basicDecoderV1('a:1:{s:3:"foo";d:1.2379813738877118E+19;}', 0x01000004, 0, $options); 279 $this->assertEquals(["foo" => 0xabcdef0123456789], $res); 280 281 $res = \Couchbase\basicDecoderV1(hex2bin("0000000214011103666f6f0c43e579bde02468ad"), 0x01000005, 0, $options); 282 if (\Couchbase\HAVE_IGBINARY) { 283 $this->assertEquals(["foo" => 0xabcdef0123456789], $res); 284 } else { 285 $this->assertEquals(NULL, $res); 286 } 287 288 $options['jsonassoc'] = false; // jsonassoc does not affect "binary" encoders 289 $res = \Couchbase\basicDecoderV1('a:1:{s:3:"foo";d:1.2379813738877118E+19;}', 0x01000004, 0, $options); 290 $this->assertEquals(["foo" => 0xabcdef0123456789], $res); 291 292 $res = \Couchbase\basicDecoderV1(hex2bin("0000000214011103666f6f0c43e579bde02468ad"), 0x01000005, 0, $options); 293 if (\Couchbase\HAVE_IGBINARY) { 294 $this->assertEquals(["foo" => 0xabcdef0123456789], $res); 295 } else { 296 $this->assertEquals(NULL, $res); 297 } 298 299 $res = \Couchbase\basicDecoderV1("1.0", 0x02000002, 0, $options); 300 $this->assertEquals(1.0, $res); 301 302 $options['jsonassoc'] = true; 303 if (\Couchbase\HAVE_ZLIB) { 304 $res = \Couchbase\basicDecoderV1(hex2bin('1b000000789cab564acbcf57b232d4333236b7b430343637b6b030374fd536b4ac0500626f06cd'), 0x01000036, 0, $options); 305 $this->assertEquals(["foo" => 0xabcdef0123439800], $res); 306 307 $res = \Couchbase\basicDecoderV1(hex2bin('1d000000789cab564acbcf57b25230343236b7b430343637b6b030373734b4303631ad05006da106fb'), 0x01000030, 0, $options); 308 $this->assertEquals('{"foo": 12379813738877118345}', $res); 309 } 310 311 $res = \Couchbase\basicDecoderV1(hex2bin('1b0000001a7b22666f6f223a312e32333739383133373338383737652b31397d'), 0x01000056, 0, $options); 312 $this->assertEquals(["foo" => 0xabcdef0123439800], $res); 313 314 $res = \Couchbase\basicDecoderV1(hex2bin('1e0000001d7b22666f6f223a312e32333739383133373338383737313138652b31397d'), 0x01000056, 0, $options); 315 $this->assertEquals(["foo" => 0xabcdef0123456789], $res); 316 317 $res = \Couchbase\basicDecoderV1('{"foo":"bar"', 0x04000000, 0, $options); 318 $this->assertEquals('{"foo":"bar"', $res); 319 320 $res = \Couchbase\basicDecoderV1('{"foo":"bar"', 0x02000000, 0, $options); 321 $this->assertEquals(null, $res); 322 $this->assertEquals(JSON_ERROR_SYNTAX, json_last_error()); 323 324 $res = \Couchbase\basicDecoderV1('{"foo":"bar"}{"baz":42}', 0x02000000, 0, $options); 325 $this->assertEquals(null, $res); 326 $this->assertEquals(JSON_ERROR_SYNTAX, json_last_error()); 327 } 328 329 function testInvalidInputForPhpSerialize() { 330 $res = \Couchbase\basicDecoderV1('foobar', 0x01000004, 0, []); 331 $this->assertNull($res); 332 } 333 334 /** 335 * @expectedException PHPUnit_Framework_Error 336 * @expectedExceptionMessageRegExp /igbinary_unserialize_header/ 337 */ 338 function testInvalidInputForIgbinary() { 339 if (!\Couchbase\HAVE_IGBINARY) { 340 $this->markTestSkipped('Extension does not support IGBINARY serializer'); 341 } 342 \Couchbase\basicDecoderV1(hex2bin("00000214011103666f6f0c43e579bde02468ad"), 0x01000005, 0, []); 343 } 344 345 function testCouchbaseDefaultEncoder() { 346 $orig = ini_get('couchbase.encoder.format'); 347 ini_set('couchbase.encoder.format', 'json'); 348 $res = \Couchbase\defaultEncoder(["foo" => 0xabcdef0123456789]); 349 $this->assertEquals(COUCHBASE_COMPRESSION_NONE, $res[1] & COUCHBASE_COMPRESSION_MASK); 350 $this->assertEquals(COUCHBASE_CFFMT_JSON, $res[1] & COUCHBASE_CFFMT_MASK); 351 $this->assertEquals(COUCHBASE_VAL_IS_JSON, $res[1] & COUCHBASE_VAL_MASK); 352 if (phpversion() >= 7.1) { 353 $this->assertEquals(['{"foo":1.2379813738877118e+19}', 0x02000006, 0], $res); 354 } else { 355 $this->assertEquals(['{"foo":1.2379813738877e+19}', 0x02000006, 0], $res); 356 } 357 358 ini_set('couchbase.encoder.format', 'php'); 359 $res = \Couchbase\defaultEncoder(["foo" => 0xabcdef0123456789]); 360 $this->assertEquals(COUCHBASE_COMPRESSION_NONE, $res[1] & COUCHBASE_COMPRESSION_MASK); 361 $this->assertEquals(COUCHBASE_CFFMT_PRIVATE, $res[1] & COUCHBASE_CFFMT_MASK); 362 $this->assertEquals(COUCHBASE_VAL_IS_SERIALIZED, $res[1] & COUCHBASE_VAL_MASK); 363 $this->assertEquals(['a:1:{s:3:"foo";d:1.2379813738877118E+19;}', 0x01000004, 0], $res); 364 ini_set('couchbase.encoder.format', $orig); 365 } 366 367 function testCouchbaseDefaultDecoder() { 368 $orig = ini_get('couchbase.decoder.json_arrays'); 369 ini_set('couchbase.decoder.json_array', false); 370 $res = \Couchbase\defaultDecoder('{"foo":1.2379813738877e+19}', 0x02000006, 0); 371 $this->assertEquals($res, (object)["foo" => 0xabcdef0123439800]); 372 373 ini_set('couchbase.decoder.json_arrays', true); 374 $res = \Couchbase\defaultDecoder('{"foo":1.2379813738877e+19}', 0x02000006, 0); 375 $this->assertEquals(["foo" => 0xabcdef0123439800], $res); 376 377 ini_set('couchbase.decoder.json_arrays', $orig); 378 } 379} 380