*/
public function exceptionGenerator($req)
{
- throw new Exception("it's just a test", 1);
+ $errNum = 1;
+ if ($req->getNumParams()) {
+ $p1 = $req->getParam(0);
+ if ($p1->kindOf() === 'scalar') {
+ $errNum = (int)$p1->scalarval();
+ }
+ }
+ throw new Exception("it's just a test", $errNum);
+ }
+
+ /**
+ * Method used to test catching of errors in the server.
+ * @param PhpXmlRpc\Request $req
+ * @throws Exception
+ */
+ public function errorGenerator($req)
+ {
+ throw new Error("it's just a test", 1);
}
/**
"tests.raiseException" => array(
"function" => array($instance, "exceptionGenerator"),
),
+ "tests.raiseError" => array(
+ "function" => array($instance, "errorGenerator"),
+ ),
)
);
output("Double: <PRE>" . htmlentities($v->serialize()) . "</PRE>");
$v = new PhpXmlRpc\Value(time(), 'dateTime.iso8601');
-output("Datetime: <PRE>" . htmlentities($v->serialize()) . "</PRE>");
+output("Datetime (from timestamp): <PRE>" . htmlentities($v->serialize()) . "</PRE>");
+$v = new PhpXmlRpc\Value(new DateTime(), 'dateTime.iso8601');
+output("Datetime (from php DateTime): <PRE>" . htmlentities($v->serialize()) . "</PRE>");
$v = new PhpXmlRpc\Value('hello world', 'base64');
output("Base64: <PRE>" . htmlentities($v->serialize()) . "</PRE>");
public function testCatchExceptions()
{
+ // this tests for the server to catch exceptions with erro code 0
$m = new xmlrpcmsg('tests.raiseException', array(
- new xmlrpcval('whatever', 'string'),
+ new xmlrpcval(0, 'int'),
+ ));
+ $v = $this->send($m, $GLOBALS['xmlrpcerr']['server_error']);
+
+ // these test for the different server exception catching modes
+ $m = new xmlrpcmsg('tests.raiseException', array(
+ new xmlrpcval(3, 'int'),
));
$v = $this->send($m, $GLOBALS['xmlrpcerr']['server_error']);
$this->addQueryParams(array('EXCEPTION_HANDLING' => 1));
+ $v = $this->send($m, 3); // the error code of the expected exception
+ $this->addQueryParams(array('EXCEPTION_HANDLING' => 2));
+ // depending on whether display_errors is ON or OFF on the server, we will get back a different error here,
+ // as php will generate an http status code of either 200 or 500...
+ $v = $this->send($m, array($GLOBALS['xmlrpcerr']['invalid_return'], $GLOBALS['xmlrpcerr']['http_error']));
+ }
+
+ public function testCatchErrors()
+ {
+ // these test for the different server error catching modes
+ $m = new xmlrpcmsg('tests.raiseError');
+ $v = $this->send($m, $GLOBALS['xmlrpcerr']['server_error']);
+ $this->addQueryParams(array('EXCEPTION_HANDLING' => 1));
$v = $this->send($m, 1); // the error code of the expected exception
$this->addQueryParams(array('EXCEPTION_HANDLING' => 2));
// depending on whether display_errors is ON or OFF on the server, we will get back a different error here,
public function getSingleHttpTestMethods()
{
$unsafeMethods = array(
- 'testCatchExceptions', 'testUtf8Method', 'testServerComments',
+ 'testCatchExceptions', 'testCatchErrors', 'testUtf8Method', 'testServerComments',
'testExoticCharsetsRequests', 'testExoticCharsetsRequests2', 'testExoticCharsetsRequests3',
'testWrapInexistentUrl',
);
$this->args = argParser::getArgs();
// assumes HTTPURI to be in the form /tests/index.php?etc...
- $this->baseUrl = $this->args['HTTPSERVER'] . preg_replace('|\?.+|', '', $this->args['HTTPURI']);
+ $this->baseUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|\?.+|', '', $this->args['HTTPURI']);
$this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|/tests/index\.php(\?.*)?|', '/tests/phpunit_coverage.php', $this->args['HTTPURI']);
}
public function testCodegenServer()
{
- /// @todo add a couple of proper xmlrpc calls, too
$page = $this->request('?demo=server/codegen.php');
$this->assertStringContainsString('<name>faultCode</name>', $page);
$this->assertRegexp('#<int>10(5|3)</int>#', $page);
+
+ $c = $this->getClient('?demo=server/codegen.php');
+ $r = $c->send(new \PhpXmlRpc\Request('CommentManager.getComments', array(
+ new \PhpXmlRpc\Value('aCommentId')
+ )));
+ $this->assertEquals(0, $r->faultCode());
}
public function testDiscussServer()
{
- /// @todo add a couple of proper xmlrpc calls, too
$page = $this->request('?demo=server/discuss.php');
$this->assertStringContainsString('<name>faultCode</name>', $page);
$this->assertRegexp('#<int>10(5|3)</int>#', $page);
+
+ $c = $this->getClient('?demo=server/discuss.php');
+
+ $r = $c->send(new \PhpXmlRpc\Request('discuss.addComment', array(
+ new \PhpXmlRpc\Value('aCommentId'),
+ new \PhpXmlRpc\Value('aCommentUser'),
+ new \PhpXmlRpc\Value('a Comment')
+ )));
+ $this->assertEquals(0, $r->faultCode());
+ $this->assertGreaterThanOrEqual(1, $r->value()->scalarval());
+
+ $r = $c->send(new \PhpXmlRpc\Request('discuss.getComments', array(
+ new \PhpXmlRpc\Value('aCommentId')
+ )));
+ $this->assertEquals(0, $r->faultCode());
+ $this->assertEquals(0, $r->faultCode());
+ $this->assertGreaterThanOrEqual(1, count($r->value()));
}
public function testProxyServer()
$this->args = argParser::getArgs();
// assumes HTTPURI to be in the form /tests/index.php?etc...
- $this->baseUrl = $this->args['HTTPSERVER'] . preg_replace('|\?.+|', '', $this->args['HTTPURI']);
+ $this->baseUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|\?.+|', '', $this->args['HTTPURI']);
$this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|/tests/index\.php(\?.*)?|', '/tests/phpunit_coverage.php', $this->args['HTTPURI']);
}
return $page;
}
+
+ protected function getClient($path)
+ {
+ $client = new xmlrpc_client($this->baseUrl . $path);
+ if ($this->collectCodeCoverageInformation) {
+ $client->setCookie('PHPUNIT_SELENIUM_TEST_ID', $this->testId);
+ }
+ $client->setAcceptedCompression(false);
+ $client->setDebug($this->args['DEBUG']);
+ return $client;
+ }
}