Add one more test for wrapped php functions: preserve php objects in results
authorgggeek <giunta.gaetano@gmail.com>
Sun, 24 May 2015 00:59:27 +0000 (01:59 +0100)
committergggeek <giunta.gaetano@gmail.com>
Sun, 24 May 2015 00:59:27 +0000 (01:59 +0100)
demo/server/server.php
tests/3LocalhostTest.php

index 3880428..e2e3c6f 100644 (file)
@@ -54,6 +54,7 @@ class xmlrpcServerMethodsContainer
 
     /**
      * A PHP version of the state-number server. Send me an integer and i'll sell you a state.
+     * Used to test wrapping of PHP methods into xmlrpc methods.
      *
      * @param integer $num
      * @return string
@@ -63,6 +64,17 @@ class xmlrpcServerMethodsContainer
     {
         return inner_findstate($num);
     }
+
+    /**
+     * Returns an instance of stdClass.
+     * Used to test wrapping of PHP objects with class preservation
+     */
+    public function returnObject()
+    {
+        $obj = new stdClass();
+        $obj->hello = 'world';
+        return $obj;
+    }
 }
 
 // a PHP version of the state-number server
@@ -172,6 +184,8 @@ $findstate11_sig = $wrapper->wrap_php_function(function ($stateNo) { return inne
 $c = new xmlrpcServerMethodsContainer;
 $moreSignatures = $wrapper->wrap_php_class($c, array('prefix' => 'tests.', 'method_type' => 'all'));
 
+$returnObj_sig =  $wrapper->wrap_php_function(array($c, 'returnObject'), '', array('encode_php_objs' => true));
+
 $addtwo_sig = array(array(Value::$xmlrpcInt, Value::$xmlrpcInt, Value::$xmlrpcInt));
 $addtwo_doc = 'Add two integers together and return the result';
 function addTwo($req)
@@ -326,8 +340,7 @@ function ageSorter($req)
     }
 }
 
-// signature and instructions, place these in the dispatch
-// map
+// signature and instructions, place these in the dispatch map
 $mailsend_sig = array(array(
     Value::$xmlrpcBoolean, Value::$xmlrpcString, Value::$xmlrpcString,
     Value::$xmlrpcString, Value::$xmlrpcString, Value::$xmlrpcString,
@@ -895,6 +908,8 @@ $signatures = array(
     'tests.getStateName.9' => $findstate9_sig,
     'tests.getStateName.10' => $findstate10_sig,
     'tests.getStateName.11' => $findstate11_sig,
+
+    'tests.returnPhpObject' => $returnObj_sig,
 );
 
 $signatures = array_merge($signatures, $moreSignatures);
index ec3ba17..4b721d6 100644 (file)
@@ -689,10 +689,10 @@ And turned it into nylon';
             $this->fail('Registration of examples.getStateName failed');
         } else {
             $v = $func(23);
-            // work around bug in current version of phpunit
-            if (is_object($v)) {
+            // work around bug in current (or old?) version of phpunit when reporting the error
+            /*if (is_object($v)) {
                 $v = var_export($v, true);
-            }
+            }*/
             $this->assertEquals('Michigan', $v);
         }
     }
@@ -707,10 +707,10 @@ And turned it into nylon';
             eval($func['source']);
             $func = $func['function'];
             $v = $func(23);
-            // work around bug in current version of phpunit
-            if (is_object($v)) {
+            // work around bug in current (or old?) version of phpunit when reporting the error
+            /*if (is_object($v)) {
                 $v = var_export($v, true);
-            }
+            }*/
             $this->assertEquals('Michigan', $v);
         }
     }
@@ -725,14 +725,29 @@ And turned it into nylon';
         } else {
             $obj = new $class();
             $v = $obj->examples_getStateName(23);
-            // work around bug in current version of phpunit
-            if (is_object($v)) {
+            // work around bug in current (or old?) version of phpunit when reporting the error
+            /*if (is_object($v)) {
                 $v = var_export($v, true);
-            }
+            }*/
             $this->assertEquals('Michigan', $v);
         }
     }
 
+    public function testTransferOfObjectViaWrapping()
+    {
+        // make a 'deep client copy' as the original one might have many properties set
+        $func = wrap_xmlrpc_method($this->client, 'tests.returnPhpObject', array('simple_client_copy' => true,
+            'decode_php_objs' => true));
+        if ($func == false) {
+            $this->fail('Registration of tests.returnPhpObject failed');
+        } else {
+            $v = $func();
+            $obj = new stdClass();
+            $obj->hello = 'world';
+            $this->assertEquals($obj, $v);
+        }
+    }
+
     public function testGetCookies()
     {
         // let server set to us some cookies we tell it