From: gggeek Date: Sun, 29 Mar 2015 14:35:48 +0000 (+0100) Subject: Move debugger to new api and add basic unit tests for it X-Git-Tag: 4.0.0-alpha^2~117 X-Git-Url: http://git.onelab.eu/?p=plcapi.git;a=commitdiff_plain;h=c8a412d48733f671db6ba149659b816c2e14fd3a Move debugger to new api and add basic unit tests for it --- diff --git a/debugger/action.php b/debugger/action.php index 2e5e4c5..f77c876 100644 --- a/debugger/action.php +++ b/debugger/action.php @@ -91,31 +91,33 @@ include __DIR__ . '/common.php'; if ($action) { + include_once __DIR__ . "/../src/Autoloader.php"; + PhpXmlRpc\Autoloader::register(); + // make sure the script waits long enough for the call to complete... if ($timeout) { set_time_limit($timeout + 10); } - include 'xmlrpc.inc'; if ($wstype == 1) { @include 'jsonrpc.inc'; if (!class_exists('jsonrpc_client')) { die('Error: to debug the jsonrpc protocol the jsonrpc.inc file is needed'); } - $clientclass = 'jsonrpc_client'; - $msgclass = 'jsonrpcmsg'; - $protoname = 'JSONRPC'; + $clientClass = 'PhpJsRpc\client'; + $requestClass = 'PhpJsRpc\request'; + $protoName = 'JSONRPC'; } else { - $clientclass = 'xmlrpc_client'; - $msgclass = 'xmlrpcmsg'; - $protoname = 'XMLRPC'; + $clientClass = 'PhpXmlRpc\client'; + $requestClass = 'PhpXmlRpc\Request'; + $protoName = 'XMLRPC'; } if ($port != "") { - $client = new $clientclass($path, $host, $port); + $client = new $clientClass($path, $host, $port); $server = "$host:$port$path"; } else { - $client = new $clientclass($path, $host); + $client = new $clientClass($path, $host); $server = "$host$path"; } if ($protocol == 2) { @@ -189,30 +191,24 @@ if ($action) { $msg = array(); switch ($action) { - - case 'wrap': - @include 'xmlrpc_wrappers.inc'; - if (!function_exists('build_remote_method_wrapper_code')) { - die('Error: to enable creation of method stubs the xmlrpc_wrappers.inc file is needed'); - } // fall thru intentionally case 'describe': case 'wrap': - $msg[0] = new $msgclass('system.methodHelp', array(), $id); - $msg[0]->addparam(new xmlrpcval($method)); - $msg[1] = new $msgclass('system.methodSignature', array(), $id + 1); - $msg[1]->addparam(new xmlrpcval($method)); + $msg[0] = new $requestClass('system.methodHelp', array(), $id); + $msg[0]->addparam(new PhpXmlRpc\Value($method)); + $msg[1] = new $requestClass('system.methodSignature', array(), $id + 1); + $msg[1]->addparam(new PhpXmlRpc\Value($method)); $actionname = 'Description of method "' . $method . '"'; break; case 'list': - $msg[0] = new $msgclass('system.listMethods', array(), $id); + $msg[0] = new $requestClass('system.listMethods', array(), $id); $actionname = 'List of available methods'; break; case 'execute': if (!payload_is_safe($payload)) { die("Tsk tsk tsk, please stop it or I will have to call in the cops!"); } - $msg[0] = new $msgclass($method, array(), $id); + $msg[0] = new $requestClass($method, array(), $id); // hack! build xml payload by hand if ($wstype == 1) { $msg[0]->payload = "{\n" . @@ -256,7 +252,7 @@ if ($action) { $time = (float)$mtime[0] + (float)$mtime[1]; foreach ($msg as $message) { // catch errors: for older xmlrpc libs, send does not return by ref - @$response = &$client->send($message, $timeout, $httpprotocol); + @$response = $client->send($message, $timeout, $httpprotocol); $resp[] = $response; if (!$response || $response->faultCode()) { break; @@ -272,14 +268,14 @@ if ($action) { if ($response->faultCode()) { // call failed! echo out error msg! //echo '

'.htmlspecialchars($actionname).' on server '.htmlspecialchars($server).'

'; - echo "

$protoname call FAILED!

\n"; + echo "

$protoName call FAILED!

\n"; echo "

Fault code: [" . htmlspecialchars($response->faultCode()) . "] Reason: '" . htmlspecialchars($response->faultString()) . "'

\n"; echo(strftime("%d/%b/%Y:%H:%M:%S\n")); } else { // call succeeded: parse results //echo '

'.htmlspecialchars($actionname).' on server '.htmlspecialchars($server).'

'; - printf("

%s call(s) OK (%.2f secs.)

\n", $protoname, $time); + printf("

%s call(s) OK (%.2f secs.)

\n", $protoName, $time); echo(strftime("%d/%b/%Y:%H:%M:%S\n")); switch ($action) { @@ -324,7 +320,7 @@ if ($action) { ""); //echo("\n"); - // generate lo scheletro per il method payload per eventuali test + // generate the skeleton for method payload per possible tests //$methodpayload="\n".$rec->scalarval()."\n\n\n\n"; /*echo ("
". @@ -388,7 +384,7 @@ if ($action) { echo 'Unknown'; } echo ''; - //bottone per testare questo metodo + // button to test this method //$payload="\n$method\n\n$payload\n"; echo "" . "" . @@ -462,7 +458,8 @@ if ($action) { echo "Error: signature unknown\n"; } else { $mdesc = $r1->scalarval(); - $msig = php_xmlrpc_decode($r2); + $encoder = new PhpXmlRpc\Encoder(); + $msig = $encoder->decode($r2); $msig = $msig[$methodsig]; $proto = $protocol == 2 ? 'https' : $protocol == 1 ? 'http11' : ''; if ($proxy == '' && $username == '' && !$requestcompression && !$responsecompression && @@ -478,7 +475,8 @@ if ($action) { $prefix = 'xmlrpc'; } //$code = wrap_xmlrpc_method($client, $method, $methodsig, 0, $proto, '', $opts); - $code = build_remote_method_wrapper_code($client, $method, str_replace('.', '_', $prefix . '_' . $method), $msig, $mdesc, $timeout, $proto, $opts, $prefix); + $wrapper = new PhpXmlRpc\Wrapper(); + $code = $wrapper->build_remote_method_wrapper_code($client, $method, str_replace('.', '_', $prefix . '_' . $method), $msig, $mdesc, $timeout, $proto, $opts, $prefix); //if ($code) //{ echo "
\n"; diff --git a/debugger/common.php b/debugger/common.php index 642326a..e8ad64c 100644 --- a/debugger/common.php +++ b/debugger/common.php @@ -4,6 +4,8 @@ * @copyright (C) 2005-2015 G. Giunta * @license code licensed under the BSD License: see file license.txt * + * Parses GET/POST variables + * * @todo switch params for http compression from 0,1,2 to values to be used directly * @todo do some more sanitization of received parameters */ diff --git a/debugger/controller.php b/debugger/controller.php index d5c8610..6051f92 100644 --- a/debugger/controller.php +++ b/debugger/controller.php @@ -18,8 +18,8 @@ if ($action == '') { } // relative path to the visual xmlrpc editing dialog -$editorpath = '../../javascript/debugger/'; -$editorlibs = '../../javascript/lib/'; +$editorpath = '../../phpjsrpc/debugger/'; +$editorlibs = '../../phpjsrpc/lib/'; ?> @@ -224,15 +224,12 @@ $editorlibs = '../../javascript/lib/'; echo ' document.forms[2].submit();'; } ?>">

XMLRPC - +
/ -
- JSONRPC Debugger (based on the PHP-XMLRPC library) +
+ JSONRPC Debugger (based on the PHP-XMLRPC library)

-
+ @@ -250,19 +247,10 @@ $editorlibs = '../../javascript/lib/';
- - - - + + + +

Action

List available methods onclick="switchaction();"/>Describe method onclick="switchaction();"/>Execute method onclick="switchaction();"/>Generate stub for method call onclick="switchaction();"/>List available methods onclick="switchaction();"/>Describe method onclick="switchaction();"/>Execute method onclick="switchaction();"/>Generate stub for method call onclick="switchaction();"/>
@@ -273,13 +261,10 @@ $editorlibs = '../../javascript/lib/'; Name: Payload:
-
- - Msg id: + + Msg id: @@ -290,38 +275,18 @@ $editorlibs = '../../javascript/lib/';

Client options

Show debug info: Timeout: - + Protocol: @@ -332,18 +297,9 @@ $editorlibs = '../../javascript/lib/'; Type @@ -351,23 +307,12 @@ $editorlibs = '../../javascript/lib/'; SSL: Verify Host's CN: Verify Cert: - /> + /> CA Cert file: @@ -384,44 +329,22 @@ $editorlibs = '../../javascript/lib/'; COMPRESSION: Request: Response: COOKIES: - + Format: 'cookie1=value1, cookie2=value2' diff --git a/debugger/index.html b/debugger/index.html deleted file mode 100644 index 87c75b9..0000000 --- a/debugger/index.html +++ /dev/null @@ -1,11 +0,0 @@ - - - -XMLRPC Debugger - - - - - - \ No newline at end of file diff --git a/src/Wrapper.php b/src/Wrapper.php index fa32781..c5d6c47 100644 --- a/src/Wrapper.php +++ b/src/Wrapper.php @@ -714,7 +714,7 @@ class Wrapper * valid php code is emitted. * Note: real spaghetti code follows... */ - protected function build_remote_method_wrapper_code($client, $methodname, $xmlrpcfuncname, + public function build_remote_method_wrapper_code($client, $methodname, $xmlrpcfuncname, $msig, $mdesc = '', $timeout = 0, $protocol = '', $client_copy_mode = 0, $prefix = 'xmlrpc', $decode_php_objects = false, $encode_php_objects = false, $decode_fault = false, $fault_response = '', $namespace = '\\PhpXmlRpc\\') diff --git a/tests/5DemofilesTest.php b/tests/5DemofilesTest.php index 48b8489..8f790d3 100644 --- a/tests/5DemofilesTest.php +++ b/tests/5DemofilesTest.php @@ -70,6 +70,9 @@ class DemoFilesTest extends PHPUnit_Framework_TestCase { curl_setopt($ch, CURLOPT_COOKIE, 'PHPUNIT_SELENIUM_TEST_ID=true'); } + if ($this->args['DEBUG'] > 0) { + curl_setopt($ch, CURLOPT_VERBOSE, 1); + } $page = curl_exec($ch); curl_close($ch); diff --git a/tests/6DebuggerTest.php b/tests/6DebuggerTest.php new file mode 100644 index 0000000..6291fef --- /dev/null +++ b/tests/6DebuggerTest.php @@ -0,0 +1,102 @@ +testId = get_class($this) . '__' . $this->getName(); + + if ($result === NULL) { + $result = $this->createResult(); + } + + $this->collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation(); + + parent::run($result); + + if ($this->collectCodeCoverageInformation) { + $coverage = new PHPUnit_Extensions_SeleniumCommon_RemoteCoverage( + $this->coverageScriptUrl, + $this->testId + ); + $result->getCodeCoverage()->append( + $coverage->get(), $this + ); + } + + // do not call this before to give the time to the Listeners to run + //$this->getStrategy()->endOfTest($this->session); + + return $result; + } + + public function setUp() + { + $this->args = argParser::getArgs(); + + $this->baseUrl = $this->args['LOCALSERVER'] . str_replace( '/demo/server/server.php', '/debugger/', $this->args['URI'] ); + + $this->coverageScriptUrl = 'http://' . $this->args['LOCALSERVER'] . '/' . str_replace( '/demo/server/server.php', 'tests/phpunit_coverage.php', $this->args['URI'] ); + } + + protected function request($file, $method = 'GET', $payload = '') + { + $url = $this->baseUrl . $file; + + $ch = curl_init($url); + curl_setopt_array($ch, array( + CURLOPT_RETURNTRANSFER => true, + CURLOPT_FAILONERROR => true + )); + if ($method == 'POST') + { + curl_setopt_array($ch, array( + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => $payload + )); + } + if ($this->collectCodeCoverageInformation) + { + curl_setopt($ch, CURLOPT_COOKIE, 'PHPUNIT_SELENIUM_TEST_ID=true'); + } + if ($this->args['DEBUG'] > 0) { + curl_setopt($ch, CURLOPT_VERBOSE, 1); + } + $page = curl_exec($ch); + curl_close($ch); + + $this->assertNotFalse($page); + $this->assertNotContains('Fatal error', $page); + $this->assertNotContains('Notice:', $page); + + return $page; + } + + public function testController() + { + $page = $this->request('controller.php'); + } + + /** + * @todo test: + * - list methods + * - describe a method + * - execute a method + * - wrap a method + */ + public function testAction() + { + $page = $this->request('action.php'); + } +}