Skip to content

Commit

Permalink
Add a test for wrapping closures
Browse files Browse the repository at this point in the history
  • Loading branch information
gggeek committed May 23, 2015
1 parent fad2b47 commit 2503e40
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
11 changes: 4 additions & 7 deletions demo/server/server.php
Expand Up @@ -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');
Expand All @@ -163,11 +158,13 @@ function inner_findstate($stateNo)
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'));

Expand Down Expand Up @@ -893,7 +890,7 @@ function i_whichToolkit($req)
'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);
Expand Down
21 changes: 15 additions & 6 deletions tests/3LocalhostTest.php
Expand Up @@ -556,7 +556,7 @@ public function testCodeInjectionServerSide()
}
}

public function testAutoRegisteredFunction()
public function testServerWrappedFunction()
{
$f = new xmlrpcmsg('tests.getStateName.2', array(
new xmlrpcval(23, 'int'),
Expand All @@ -565,7 +565,7 @@ public function testAutoRegisteredFunction()
$this->assertEquals('Michigan', $v->scalarval());
}

public function testAutoRegisteredFunction2()
public function testServerWrappedFunctionAsSource()
{
$f = new xmlrpcmsg('tests.getStateName.6', array(
new xmlrpcval(23, 'int'),
Expand All @@ -574,7 +574,7 @@ public function testAutoRegisteredFunction2()
$this->assertEquals('Michigan', $v->scalarval());
}

public function testAutoRegisteredMethods()
public function testServerWrappedObjectMethods()
{
$f = new xmlrpcmsg('tests.getStateName.3', array(
new xmlrpcval(23, 'int'),
Expand Down Expand Up @@ -613,7 +613,7 @@ public function testAutoRegisteredMethods()
$this->assertEquals('Michigan', $v->scalarval());
}

public function testAutoRegisteredMethods2()
public function testServerWrappedObjectMethodsAsSource()
{
$f = new xmlrpcmsg('tests.getStateName.7', array(
new xmlrpcval(23, 'int'),
Expand All @@ -634,7 +634,7 @@ public function testAutoRegisteredMethods2()
$this->assertEquals('Michigan', $v->scalarval());
}

public function testAutoRegisteredClosure()
public function testServerClosure()
{
$f = new xmlrpcmsg('tests.getStateName.10', array(
new xmlrpcval(23, 'int'),
Expand All @@ -643,7 +643,16 @@ public function testAutoRegisteredClosure()
$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'),
Expand Down

0 comments on commit 2503e40

Please sign in to comment.