예제 #1
0
 function testCallMessage()
 {
     $tests = [["in" => '[48,12345,{},"com.example.rpc"]', "out" => '[48,12345,{},"com.example.rpc"]'], ["in" => '[48,12345,{},"com.example.rpc", [], {}]', "out" => '[48,12345,{},"com.example.rpc"]'], ["in" => '[48,12345,{},"com.example.rpc", [], {"test": "something"}]', "out" => '[48,12345,{},"com.example.rpc",[],{"test":"something"}]'], ["in" => '[48,12345,{},"com.example.rpc", [{"test":"something"}], {}]', "out" => '[48,12345,{},"com.example.rpc",[{"test":"something"}]]'], ["in" => '[8,48,12345,{},"some.error.uri"]', "out" => '[8,48,12345,{},"some.error.uri"]'], ["in" => '[8,48,12345,{},"some.error.uri",[],{}]', "out" => '[8,48,12345,{},"some.error.uri"]'], ["in" => '[8,48,12345,{},"some.error.uri",[], {"test": "something"}]', "out" => '[8,48,12345,{},"some.error.uri",[],{"test":"something"}]'], ["in" => '[8,48,12345,{},"some.error.uri",[{"test":"something"}], {}]', "out" => '[8,48,12345,{},"some.error.uri",[{"test":"something"}]]'], ["in" => '[16, 239714735, {}, "com.myapp.mytopic1", [], {"color": "orange", "sizes": [23, 42, 7]}]', "out" => '[16,239714735,{},"com.myapp.mytopic1",[],{"color":"orange","sizes":[23,42,7]}]'], ["in" => '[16, 239714735, {}, "com.myapp.mytopic1", [], {"color": "orange", "sizes": [23, 42, 7]}]', "out" => '[16,239714735,{},"com.myapp.mytopic1",[],{"color":"orange","sizes":[23,42,7]}]'], ["in" => '[16, 239714735, {}, "com.myapp.mytopic1", [{"color": "orange", "sizes": [23, 42, 7]}],{}]', "out" => '[16,239714735,{},"com.myapp.mytopic1",[{"color":"orange","sizes":[23,42,7]}]]'], ["in" => '[36, 5512315355, 4429313566, {}]', "out" => '[36,5512315355,4429313566,{}]'], ["in" => '[36, 5512315355, 4429313566, {}, ["Hello, world!"]]', "out" => '[36,5512315355,4429313566,{},["Hello, world!"]]'], ["in" => '[36, 5512315355, 4429313566, {}, [], {"color": "orange", "sizes": [23, 42, 7]}]', "out" => '[36,5512315355,4429313566,{},[],{"color":"orange","sizes":[23,42,7]}]'], ["in" => '[50, 7814135, {}]', "out" => '[50,7814135,{}]'], ["in" => '[50, 7814135, {}, ["Hello, world!"]]', "out" => '[50,7814135,{},["Hello, world!"]]'], ["in" => '[50, 7814135, {}, [30]]', "out" => '[50,7814135,{},[30]]'], ["in" => '[50, 7814135, {}, [], {"userid": 123, "karma": 10}]', "out" => '[50,7814135,{},[],{"userid":123,"karma":10}]'], ["in" => '[68, 6131533, 9823526, {}]', "out" => '[68,6131533,9823526,{}]'], ["in" => '[68, 6131533, 9823527, {}, ["Hello, world!"]]', "out" => '[68,6131533,9823527,{},["Hello, world!"]]'], ["in" => '[68, 6131533, 9823528, {}, [23, 7]]', "out" => '[68,6131533,9823528,{},[23,7]]'], ["in" => '[68, 6131533, 9823529, {}, ["johnny"], {"firstname": "John", "surname": "Doe"}]', "out" => '[68,6131533,9823529,{},["johnny"],{"firstname":"John","surname":"Doe"}]'], ["in" => '[70,6131533,{}]', "out" => '[70,6131533,{}]'], ["in" => '[70,6131533,{},["Hello, world!"], {}]', "out" => '[70,6131533,{},["Hello, world!"]]'], ["in" => '[70,6131533,{},[],{"userid":123,"karma":10}]', "out" => '[70,6131533,{},[],{"userid":123,"karma":10}]']];
     $serializer = new JsonSerializer();
     foreach ($tests as $test) {
         $msg = $serializer->deserialize($test["in"]);
         $this->assertEquals($test['out'], $serializer->serialize($msg));
     }
 }
예제 #2
0
 function testABunchOfMessages()
 {
     $tests = [["in" => '[3, {"message": "The realm does not exist."}, "wamp.error.no_such_realm"]', "out" => '[3,{"message":"The realm does not exist."},"wamp.error.no_such_realm"]'], ["in" => '[3, {}, "wamp.error.no_such_realm"]', "out" => '[3,{},"wamp.error.no_such_realm"]'], ["in" => '[5, "gir1mSx+deCDUV7wRM5SGIn/+R/ClqLZuH4m7FJeBVI=", {}]', "out" => '[5,"gir1mSx+deCDUV7wRM5SGIn\\/+R\\/ClqLZuH4m7FJeBVI=",{}]'], ["in" => '[5, "gir1mSx+deCDUV7wRM5SGIn/+R/ClqLZuH4m7FJeBVI=", {"option_name":"option_value"}]', "out" => '[5,"gir1mSx+deCDUV7wRM5SGIn\\/+R\\/ClqLZuH4m7FJeBVI=",{"option_name":"option_value"}]'], ["in" => '[48,12345,{},"com.example.rpc"]', "out" => '[48,12345,{},"com.example.rpc"]'], ["in" => '[48,12345,{},"com.example.rpc", [], {}]', "out" => '[48,12345,{},"com.example.rpc"]'], ["in" => '[48,12345,{},"com.example.rpc", [], {"test": "something"}]', "out" => '[48,12345,{},"com.example.rpc",[],{"test":"something"}]'], ["in" => '[48,12345,{},"com.example.rpc", [{"test":"something"}], {}]', "out" => '[48,12345,{},"com.example.rpc",[{"test":"something"}]]'], ["in" => '[49,12345,{"really":true}]', "out" => '[49,12345,{"really":true}]'], ["in" => '[49,12345,{}]', "out" => '[49,12345,{}]'], ["in" => '[4, "wampcra",{"challenge": "{\\"nonce\\": \\"LHRTC9zeOIrt_9U3\\", \\"authprovider\\": \\"userdb\\", \\"authid\\": \\"peter\\",\\"timestamp\\": \\"2014-06-22T16:36:25.448Z\\", \\"authrole\\": \\"user\\",\\"authmethod\\": \\"wampcra\\", \\"session\\": 3251278072152162}"}]', "out" => '[4,"wampcra",{"challenge":"{\\"nonce\\": \\"LHRTC9zeOIrt_9U3\\", \\"authprovider\\": \\"userdb\\", \\"authid\\": \\"peter\\",\\"timestamp\\": \\"2014-06-22T16:36:25.448Z\\", \\"authrole\\": \\"user\\",\\"authmethod\\": \\"wampcra\\", \\"session\\": 3251278072152162}"}]'], ["in" => '[4,"some_auth",{}]', "out" => '[4,"some_auth",{}]'], ["in" => '[8,48,12345,{},"some.error.uri"]', "out" => '[8,48,12345,{},"some.error.uri"]'], ["in" => '[8,48,12345,{},"some.error.uri",[],{}]', "out" => '[8,48,12345,{},"some.error.uri"]'], ["in" => '[8,48,12345,{},"some.error.uri",[], {"test": "something"}]', "out" => '[8,48,12345,{},"some.error.uri",[],{"test":"something"}]'], ["in" => '[8,48,12345,{},"some.error.uri",[{"test":"something"}], {}]', "out" => '[8,48,12345,{},"some.error.uri",[{"test":"something"}]]'], ["in" => '[36, 5512315355, 4429313566, {}]', "out" => '[36,5512315355,4429313566,{}]'], ["in" => '[36, 5512315355, 4429313566, {}, ["Hello, world!"]]', "out" => '[36,5512315355,4429313566,{},["Hello, world!"]]'], ["in" => '[36, 5512315355, 4429313566, {}, [], {"color": "orange", "sizes": [23, 42, 7]}]', "out" => '[36,5512315355,4429313566,{},[],{"color":"orange","sizes":[23,42,7]}]'], ["in" => '[6, {"message": "The host is shutting down now."}, "wamp.error.system_shutdown"]', "out" => '[6,{"message":"The host is shutting down now."},"wamp.error.system_shutdown"]'], ["in" => '[6, { }, "wamp.error.system_shutdown"]', "out" => '[6,{},"wamp.error.system_shutdown"]'], ["in" => '[7, 23, 5, "throw me away ... I am just noise"]', "out" => '[7,23,5,"throw me away ... I am just noise"]'], ["in" => '[69, 12345, {}]', "out" => '[69,12345,{}]'], ["in" => '[69, 12345, {"really":"yes"}]', "out" => '[69,12345,{"really":"yes"}]'], ["in" => '[68, 6131533, 9823526, {}]', "out" => '[68,6131533,9823526,{}]'], ["in" => '[68, 6131533, 9823527, {}, ["Hello, world!"]]', "out" => '[68,6131533,9823527,{},["Hello, world!"]]'], ["in" => '[68, 6131533, 9823528, {}, [23, 7]]', "out" => '[68,6131533,9823528,{},[23,7]]'], ["in" => '[68, 6131533, 9823529, {}, ["johnny"], {"firstname": "John", "surname": "Doe"}]', "out" => '[68,6131533,9823529,{},["johnny"],{"firstname":"John","surname":"Doe"}]'], ["in" => '[16, 239714735, {}, "com.myapp.mytopic1", [], {"color": "orange", "sizes": [23, 42, 7]}]', "out" => '[16,239714735,{},"com.myapp.mytopic1",[],{"color":"orange","sizes":[23,42,7]}]'], ["in" => '[16, 239714735, {}, "com.myapp.mytopic1", [], {"color": "orange", "sizes": [23, 42, 7]}]', "out" => '[16,239714735,{},"com.myapp.mytopic1",[],{"color":"orange","sizes":[23,42,7]}]'], ["in" => '[16, 239714735, {}, "com.myapp.mytopic1", [{"color": "orange", "sizes": [23, 42, 7]}],{}]', "out" => '[16,239714735,{},"com.myapp.mytopic1",[{"color":"orange","sizes":[23,42,7]}]]'], ["in" => '[17, 239714735, 4429313566]', "out" => '[17,239714735,4429313566]'], ["in" => '[65, 25349185, 2103333224]', "out" => '[65,25349185,2103333224]'], ["in" => '[64, 25349185, {}, "com.myapp.myprocedure1"]', "out" => '[64,25349185,{},"com.myapp.myprocedure1"]'], ["in" => '[50, 7814135, {}]', "out" => '[50,7814135,{}]'], ["in" => '[50, 7814135, {}, []]', "out" => '[50,7814135,{}]'], ["in" => '[50, 7814135, {}, ["Hello, world!"]]', "out" => '[50,7814135,{},["Hello, world!"]]'], ["in" => '[50, 7814135, {}, [30]]', "out" => '[50,7814135,{},[30]]'], ["in" => '[50, 7814135, {}, [], {"userid": 123, "karma": 10}]', "out" => '[50,7814135,{},[],{"userid":123,"karma":10}]'], ["in" => '[33, 713845233, 5512315355]', "out" => '[33,713845233,5512315355]'], ["in" => '[32, 713845233, {}, "com.myapp.mytopic1"]', "out" => '[32,713845233,{},"com.myapp.mytopic1"]'], ["in" => '[67, 788923562]', "out" => '[67,788923562]'], ["in" => '[66, 788923562, 2103333224]', "out" => '[66,788923562,2103333224]'], ["in" => '[35, 85346237]', "out" => '[35,85346237]'], ["in" => '[34, 85346237, 5512315355]', "out" => '[34,85346237,5512315355]'], ["in" => '[70,6131533,{}]', "out" => '[70,6131533,{}]'], ["in" => '[70,6131533,{},["Hello, world!"], {}]', "out" => '[70,6131533,{},["Hello, world!"]]'], ["in" => '[70,6131533,{},[],{"userid":123,"karma":10}]', "out" => '[70,6131533,{},[],{"userid":123,"karma":10}]']];
     $serializer = new JsonSerializer();
     foreach ($tests as $test) {
         $msg = $serializer->deserialize($test["in"]);
         //$this->assertEquals($test["out"], json_encode(json_decode($test["out"])));
         $this->assertEquals($test['out'], $serializer->serialize($msg));
     }
 }