From 2503e40912ae30a40c339127519846c2f66bbd4a Mon Sep 17 00:00:00 2001 From: gggeek Date: Sat, 23 May 2015 21:14:27 +0100 Subject: [PATCH] Add a test for wrapping closures --- demo/server/server.php | 11 ++++------- tests/3LocalhostTest.php | 21 +++++++++++++++------ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/demo/server/server.php b/demo/server/server.php index 775b077..6f0a430 100644 --- a/demo/server/server.php +++ b/demo/server/server.php @@ -132,11 +132,6 @@ function inner_findstate($stateNo) } } -$findStateClosure = function ($req) -{ - return findState($req); -}; - $wrapper = new PhpXmlRpc\Wrapper(); $findstate2_sig = $wrapper->wrap_php_function('inner_findstate'); @@ -163,11 +158,13 @@ $findstate9_sig = $wrapper->wrap_php_function('xmlrpcServerMethodsContainer::fin eval($findstate9_sig['source']); $findstate10_sig = array( - "function" => $findStateClosure, + "function" => function ($req) { return findState($req); }, "signature" => $findstate_sig, "docstring" => $findstate_doc, ); +$findstate11_sig = $wrapper->wrap_php_function(function ($stateNo) { return inner_findstate($stateNo); }); + $c = new xmlrpcServerMethodsContainer; $moreSignatures = $wrapper->wrap_php_class($c, array('prefix' => 'tests.', 'method_type' => 'all')); @@ -893,7 +890,7 @@ $signatures = array( 'tests.getStateName.8' => $findstate8_sig, 'tests.getStateName.9' => $findstate9_sig, 'tests.getStateName.10' => $findstate10_sig, - + 'tests.getStateName.11' => $findstate11_sig, ); $signatures = array_merge($signatures, $moreSignatures); diff --git a/tests/3LocalhostTest.php b/tests/3LocalhostTest.php index e205c9e..f559fa6 100644 --- a/tests/3LocalhostTest.php +++ b/tests/3LocalhostTest.php @@ -556,7 +556,7 @@ And turned it into nylon'; } } - public function testAutoRegisteredFunction() + public function testServerWrappedFunction() { $f = new xmlrpcmsg('tests.getStateName.2', array( new xmlrpcval(23, 'int'), @@ -565,7 +565,7 @@ And turned it into nylon'; $this->assertEquals('Michigan', $v->scalarval()); } - public function testAutoRegisteredFunction2() + public function testServerWrappedFunctionAsSource() { $f = new xmlrpcmsg('tests.getStateName.6', array( new xmlrpcval(23, 'int'), @@ -574,7 +574,7 @@ And turned it into nylon'; $this->assertEquals('Michigan', $v->scalarval()); } - public function testAutoRegisteredMethods() + public function testServerWrappedObjectMethods() { $f = new xmlrpcmsg('tests.getStateName.3', array( new xmlrpcval(23, 'int'), @@ -613,7 +613,7 @@ And turned it into nylon'; $this->assertEquals('Michigan', $v->scalarval()); } - public function testAutoRegisteredMethods2() + public function testServerWrappedObjectMethodsAsSource() { $f = new xmlrpcmsg('tests.getStateName.7', array( new xmlrpcval(23, 'int'), @@ -634,7 +634,7 @@ And turned it into nylon'; $this->assertEquals('Michigan', $v->scalarval()); } - public function testAutoRegisteredClosure() + public function testServerClosure() { $f = new xmlrpcmsg('tests.getStateName.10', array( new xmlrpcval(23, 'int'), @@ -643,7 +643,16 @@ And turned it into nylon'; $this->assertEquals('Michigan', $v->scalarval()); } - public function testAutoRegisteredClass() + public function testServerWrappedClosure() + { + $f = new xmlrpcmsg('tests.getStateName.11', array( + new xmlrpcval(23, 'int'), + )); + $v = $this->send($f); + $this->assertEquals('Michigan', $v->scalarval()); + } + + public function testServerWrappedClass() { $f = new xmlrpcmsg('tests.xmlrpcServerMethodsContainer.findState', array( new xmlrpcval(23, 'int'), -- 2.43.0