Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

fixes #4604 #5379

Closed
wants to merge 1 commit into from

2 participants

@steverhoades

If class contains constructor addFunction will no longer result in an error. This fixes issue #4604

@weierophinney weierophinney commented on the diff
tests/ZendTest/Json/ServerTest.php
@@ -493,6 +523,38 @@ public function baz()
}
}
+class Bar
@weierophinney Owner

This should be in a separate file. I can do that on merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@weierophinney weierophinney referenced this pull request from a commit
@weierophinney weierophinney [#5379] Move test assets to separate files
- Moved classes, functions used by test case to separate files
35ec7e7
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-json
@weierophinney weierophinney [zendframework/zf2#5379] Move test assets to separate files
- Moved classes, functions used by test case to separate files
cf6868a
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-json
@weierophinney weierophinney Merge branch 'hotfix/5379' 9341798
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-json
@weierophinney weierophinney Merge branch 'hotfix/5379' into develop db6575f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 29, 2013
  1. @steverhoades
This page is out of date. Refresh to see the latest.
View
3  library/Zend/Json/Server/Server.php
@@ -86,6 +86,7 @@ public function addFunction($function, $namespace = '')
$argv = array_slice($argv, 2);
}
+ $class = null;
if (is_string($function)) {
$method = Reflection::reflectFunction($function, $argv, $namespace);
} else {
@@ -106,7 +107,7 @@ public function addFunction($function, $namespace = '')
}
}
- $definition = $this->_buildSignature($method);
+ $definition = $this->_buildSignature($method, $class);
$this->_addMethodServiceMap($definition);
return $this;
View
62 tests/ZendTest/Json/ServerTest.php
@@ -462,6 +462,36 @@ public function testLoadFunctionsShouldLoadResultOfGetFunctions()
$server->loadFunctions($functions);
$this->assertEquals($functions->toArray(), $server->getFunctions()->toArray());
}
+
+ /**
+ * @group ZF-4604
+ */
+ public function testAddFunctionAndClassThatContainsConstructor()
+ {
+ $bar = new Bar('unique');
+
+ $this->server->addFunction(array($bar, 'foo'));
+
+ $request = $this->server->getRequest();
+ $request->setMethod('foo')
+ ->setParams(array(true, 'foo', 'bar'))
+ ->setId('foo');
+ ob_start();
+ $this->server->handle();
+ $buffer = ob_get_clean();
+
+ $decoded = Json\Json::decode($buffer, Json\Json::TYPE_ARRAY);
+
+ $this->assertTrue(is_array($decoded));
+ $this->assertTrue(array_key_exists('result', $decoded));
+ $this->assertTrue(array_key_exists('id', $decoded));
+ $this->assertTrue(in_array('unique', $decoded['result']));
+
+ $response = $this->server->getResponse();
+ $this->assertEquals($response->getResult(), $decoded['result']);
+ $this->assertEquals($response->getId(), $decoded['id']);
+
+ }
}
/**
@@ -493,6 +523,38 @@ public function baz()
}
}
+class Bar
@weierophinney Owner

This should be in a separate file. I can do that on merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+{
+ protected $val;
+
+ public function __construct($someval)
+ {
+ $this->val = $someval;
+ }
+ /**
+ * Bar
+ *
+ * @param bool $one
+ * @param string $two
+ * @param mixed $three
+ * @return array
+ */
+ public function foo($one, $two = 'two', $three = null)
+ {
+ return array($one, $two, $three, $this->val);
+ }
+
+ /**
+ * Baz
+ *
+ * @return void
+ */
+ public function baz()
+ {
+ throw new \Exception('application error');
+ }
+}
+
/**
* Test function for JSON-RPC server
*
Something went wrong with that request. Please try again.