cvs: pear /SOAP/test test.utility.php
| From: | Jan Schneider | Date: | Fri, 26 Jan 2007 00:04:08 +0000 |
| Subject: | cvs: pear /SOAP/test test.utility.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-44390@lists.php.net to get a copy of this message | ||
yunosh Fri Jan 26 00:04:08 2007 UTC
Modified files:
/pear/SOAP/test test.utility.php
Log:
Add object_compare(), load dateTime.php, CS.
http://cvs.php.net/viewvc.cgi/pear/SOAP/test/test.utility.php?r1=1.12&r2=1.13&diff_format=u
Index: pear/SOAP/test/test.utility.php
diff -u pear/SOAP/test/test.utility.php:1.12 pear/SOAP/test/test.utility.php:1.13
--- pear/SOAP/test/test.utility.php:1.12 Mon Jan 22 10:43:00 2007
+++ pear/SOAP/test/test.utility.php Fri Jan 26 00:04:08 2007
@@ -23,11 +23,11 @@
function boolean_compare($f1, $f2)
{
- if (($f1 == 'true' || $f1 === TRUE || $f1 != 0) &&
- ($f2 == 'true' || $f2 === TRUE || $f2 != 0)) return TRUE;
- if (($f1 == 'false' || $f1 === FALSE || $f1 == 0) &&
- ($f2 == 'false' || $f2 === FALSE || $f2 == 0)) return TRUE;
- return FALSE;
+ if (($f1 == 'true' || $f1 === true || $f1 != 0) &&
+ ($f2 == 'true' || $f2 === true || $f2 != 0)) return true;
+ if (($f1 == 'false' || $f1 === false || $f1 == 0) &&
+ ($f2 == 'false' || $f2 === false || $f2 == 0)) return true;
+ return false;
}
function string_compare($e1, $e2)
@@ -41,8 +41,9 @@
// handle dateTime comparison
$e1_type = gettype($e1);
$e2_type = gettype($e2);
- $ok = FALSE;
+ $ok = false;
if ($e1_type == "string") {
+ require_once 'SOAP/Type/dateTime.php';
$dt = new SOAP_Type_dateTime();
$ok = $dt->compare($e1, $e2) == 0;
}
@@ -51,22 +52,34 @@
function array_compare(&$ar1, &$ar2)
{
- if (gettype($ar1) != 'array' || gettype($ar2) != 'array') return FALSE;
+ if (gettype($ar1) != 'array' || gettype($ar2) != 'array') return false;
// first a shallow diff
- if (count($ar1) != count($ar2)) return FALSE;
+ if (count($ar1) != count($ar2)) return false;
$diff = array_diff($ar1, $ar2);
- if (count($diff) == 0) return TRUE;
+ if (count($diff) == 0) return true;
// diff failed, do a full check of the array
foreach ($ar1 as $k => $v) {
//print "comparing $v == $ar2[$k]\n";
- if (gettype($v) == "array") {
- if (!array_compare($v, $ar2[$k])) return FALSE;
+ if (gettype($v) == 'array') {
+ if (!array_compare($v, $ar2[$k])) return false;
+ } elseif (is_object($v)) {
+ if (!object_compare($v, $ar2[$k])) return false;
} else {
- if (!string_compare($v, $ar2[$k])) return FALSE;
+ if (!string_compare($v, $ar2[$k])) return false;
}
}
- return TRUE;
+ return true;
+}
+
+function object_compare(&$o1, &$o2)
+{
+ if (!is_object($o1) || !is_object($o2) || gettype($o1) != gettype($o2)) {
+ return false;
+ }
+ $o1 = (array)$o1;
+ $o2 = (array)$o2;
+ return array_compare($o1, $o2);
}
function parseMessage($msg)