41 lines
1001 B
PHP
41 lines
1001 B
PHP
<?php
|
|
|
|
class RpcCommon {
|
|
protected $_test;
|
|
|
|
public function __construct(&$test) {
|
|
$this->_test = $test;
|
|
}
|
|
|
|
public function validateRpc($msg, $classMethod = null, $forcedMethod = false) {
|
|
if (is_string($msg)) {
|
|
$msg = json_decode($msg, true);
|
|
}
|
|
|
|
$this->_test->equal(1, $msg['dinetrpc']);
|
|
|
|
$time = round(microtime(true) * 1000);
|
|
$this->_test->range($msg['time'], $time - 3000, $time + 3000);
|
|
|
|
if (isset($msg['req'])) {
|
|
$this->_test->isTrue(isset($msg['id']));
|
|
$this->_test->isTrue(isset($msg['req']));
|
|
$cm = $msg['req'];
|
|
} elseif (isset($msg['rep'])) {
|
|
$this->_test->isTrue(isset($msg['id']));
|
|
$this->_test->isTrue(isset($msg['rep']));
|
|
$cm = $msg['rep'];
|
|
} elseif (isset($msg['pub'])) {
|
|
$this->_test->isTrue(isset($msg['pub']));
|
|
$cm = $msg['pub'];
|
|
} else {
|
|
$this->_test->failure('RPC message has no message type');
|
|
$this->_test->isTrue(false);
|
|
}
|
|
if ($classMethod !== null) {
|
|
$this->_test->equal($classMethod, $cm);
|
|
}
|
|
return $msg;
|
|
}
|
|
}
|