summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStig Bakken <ssb@php.net>2001-11-04 09:07:17 +0000
committerStig Bakken <ssb@php.net>2001-11-04 09:07:17 +0000
commitdb44b1086cbb06be1d3e1390d43cf6b1fecb1bf5 (patch)
tree31865f7ee1026e2ed634c134144836a4dde91ea7
parentc4b7501956cb79d729e56115a7ef17bbe8f89c22 (diff)
downloadphp-git-db44b1086cbb06be1d3e1390d43cf6b1fecb1bf5.tar.gz
* expectError() now accepts "*" as a catch-all
* updated tests
-rw-r--r--pear/PEAR.php10
-rw-r--r--pear/tests/pear_error.phpt61
-rw-r--r--pear/tests/pear_error2.phpt6
-rw-r--r--pear/tests/pear_error3.phpt8
-rw-r--r--pear/tests/pear_error4.phpt89
5 files changed, 110 insertions, 64 deletions
diff --git a/pear/PEAR.php b/pear/PEAR.php
index 1f73c0c1e2..4a6a19d6ee 100644
--- a/pear/PEAR.php
+++ b/pear/PEAR.php
@@ -286,7 +286,7 @@ class PEAR
*
* @return int the new depth of the "expected errors" stack
*/
- function expectError($code)
+ function expectError($code = "*")
{
if (is_array($code)) {
array_push($this->_expected_errors, $code);
@@ -366,8 +366,12 @@ class PEAR
$message = $message->getMessage();
}
- if (isset($this) && isset($this->_expected_errors) && sizeof($this->_expected_errors) > 0 && in_array($code, end($this->_expected_errors))) {
- $mode = PEAR_ERROR_RETURN;
+ if (isset($this) && isset($this->_expected_errors) && sizeof($this->_expected_errors) > 0 && sizeof($exp = end($this->_expected_errors))) {
+ if ($exp[0] == "*" ||
+ (is_int(reset($exp)) && in_array($code, $exp)) ||
+ (is_string(reset($exp)) && in_array($message, $exp))) {
+ $mode = PEAR_ERROR_RETURN;
+ }
}
if ($mode === null) {
diff --git a/pear/tests/pear_error.phpt b/pear/tests/pear_error.phpt
index 79267dae5d..0b7bd514e8 100644
--- a/pear/tests/pear_error.phpt
+++ b/pear/tests/pear_error.phpt
@@ -1,5 +1,5 @@
--TEST--
-PEAR_Error test
+PEAR_Error: basic test
--SKIPIF--
--FILE--
<?php // -*- PHP -*-
@@ -8,7 +8,7 @@ PEAR_Error test
// Parts tested: - PEAR_Error class
// - PEAR::isError static method
-require_once "../PEAR.php";
+require "../PEAR.php";
function test_error_handler($errno, $errmsg, $file, $line, $vars) {
$errortype = array (
@@ -122,28 +122,6 @@ print "mode=trigger,level=error:";
$err = new PEAR_Error("test error", -42, PEAR_ERROR_TRIGGER, E_USER_ERROR);
print $err->toString() . "\n";
-print "testing expectError:\n";
-$obj =& new PEAR;
-$obj->setErrorHandling(PEAR_ERROR_PRINT, "*** ERROR: %s\n");
-print "expecting syntax/invalid\n";
-$obj->expectError(array("syntax", "invalid"));
-print "raising already_exists\n";
-$err = $obj->raiseError("already_exists");
-print "raising syntax\n";
-$err = $obj->raiseError("syntax");
-print "expecting syntax only\n";
-$obj->expectError(array("syntax"));
-print "raising invalid\n";
-$err = $obj->raiseError("invalid");
-print "popping\n";
-var_dump($obj->popExpect());
-print "raising invalid\n";
-$err = $obj->raiseError("invalid");
-print "popping\n";
-var_dump($obj->popExpect());
-print "raising invalid\n";
-$err = $obj->raiseError("invalid");
-
?>
--GET--
--POST--
@@ -159,42 +137,17 @@ mode=print: test error[pear_error: message="test error" code=-42 mode=print leve
mode=callback(function): errorhandler function called, obj=[pear_error: message="test error" code=-42 mode=callback callback=errorhandler prefix="" info=""]
mode=callback(method): errorhandler method called, obj=[pear_error: message="test error" code=-42 mode=callback callback=errorclass::errorhandler prefix="" info=""]
mode=print&trigger: test error
-User Notice: test error in PEAR.php on line 591
+User Notice: test error in PEAR.php on line 595
[pear_error: message="test error" code=-42 mode=print|trigger level=notice prefix="" info=""]
mode=trigger:
-User Notice: test error in PEAR.php on line 591
+User Notice: test error in PEAR.php on line 595
[pear_error: message="test error" code=-42 mode=trigger level=notice prefix="" info=""]
mode=trigger,level=notice:
-User Notice: test error in PEAR.php on line 591
+User Notice: test error in PEAR.php on line 595
[pear_error: message="test error" code=-42 mode=trigger level=notice prefix="" info=""]
mode=trigger,level=warning:
-User Warning: test error in PEAR.php on line 591
+User Warning: test error in PEAR.php on line 595
[pear_error: message="test error" code=-42 mode=trigger level=warning prefix="" info=""]
mode=trigger,level=error:
-User Error: test error in PEAR.php on line 591
+User Error: test error in PEAR.php on line 595
[pear_error: message="test error" code=-42 mode=trigger level=error prefix="" info=""]
-testing expectError:
-expecting syntax/invalid
-raising already_exists
-*** ERROR: already_exists
-raising syntax
-*** ERROR: syntax
-expecting syntax only
-raising invalid
-*** ERROR: invalid
-popping
-array(1) {
- [0]=>
- string(6) "syntax"
-}
-raising invalid
-*** ERROR: invalid
-popping
-array(2) {
- [0]=>
- string(6) "syntax"
- [1]=>
- string(7) "invalid"
-}
-raising invalid
-*** ERROR: invalid
diff --git a/pear/tests/pear_error2.phpt b/pear/tests/pear_error2.phpt
index 8d2531380e..eef585289f 100644
--- a/pear/tests/pear_error2.phpt
+++ b/pear/tests/pear_error2.phpt
@@ -1,5 +1,5 @@
--TEST--
-PEAR_Error in die mode
+PEAR_Error: die mode
--SKIPIF--
--FILE--
<?php // -*- C++ -*-
@@ -9,9 +9,9 @@ PEAR_Error in die mode
// - PEAR::isError static method
// testing PEAR_Error
-require_once "PEAR.php";
+require "../PEAR.php";
-error_reporting(4095);
+error_reporting(E_ALL);
print "mode=die: ";
$err = new PEAR_Error("test error!!\n", -42, PEAR_ERROR_DIE);
diff --git a/pear/tests/pear_error3.phpt b/pear/tests/pear_error3.phpt
index 4703a222b6..86d82c464d 100644
--- a/pear/tests/pear_error3.phpt
+++ b/pear/tests/pear_error3.phpt
@@ -1,16 +1,16 @@
--TEST--
-PEAR default error handling
+PEAR_Error: default error handling
--FILE--
-<?php // -*- C++ -*-
+<?php // -*- PHP -*-
// Test for: PEAR.php
// Parts tested: - PEAR_Error class
// - PEAR::setErrorHandling
// - PEAR::raiseError method
-require_once "PEAR.php";
+require "../PEAR.php";
-error_reporting(4095);
+error_reporting(E_ALL);
function errorhandler($eobj)
{
diff --git a/pear/tests/pear_error4.phpt b/pear/tests/pear_error4.phpt
new file mode 100644
index 0000000000..1b50637698
--- /dev/null
+++ b/pear/tests/pear_error4.phpt
@@ -0,0 +1,89 @@
+--TEST--
+PEAR_Error: expected errors
+--FILE--
+<?php // -*- PHP -*-
+
+// Test for: PEAR.php
+// Parts tested: - PEAR_Error class
+// - PEAR::expectError
+// - PEAR::popExpect
+
+require "../PEAR.php";
+
+error_reporting(E_ALL);
+
+function errorhandler($eobj)
+{
+ if (PEAR::isError($eobj)) {
+ print "error: ".$eobj->getMessage()."\n";
+ } else {
+ print "errorhandler called without error object\n";
+ }
+}
+
+$obj = new PEAR;
+$obj->setErrorHandling(PEAR_ERROR_CALLBACK, "errorhandler");
+
+print "subtest 1\n";
+$obj->expectError(1);
+$obj->raiseError("1", 1);
+$obj->popExpect();
+$obj->raiseError("2", 2);
+
+print "subtest 2\n";
+$obj->expectError(3);
+$obj->expectError(2);
+$obj->raiseError("3", 3);
+
+print "subtest 3\n";
+$obj->popExpect();
+$obj->raiseError("3", 3);
+$obj->popExpect();
+
+print "subtest 4\n";
+$obj->expectError(array(1,2,3,4,5));
+$obj->raiseError("0", 0);
+$obj->raiseError("1", 1);
+$obj->raiseError("2", 2);
+$obj->raiseError("3", 3);
+$obj->raiseError("4", 4);
+$obj->raiseError("5", 5);
+$obj->raiseError("6", 6);
+$obj->raiseError("error");
+$obj->popExpect();
+
+print "subtest 5\n";
+$obj->expectError("*");
+$obj->raiseError("42", 42);
+$obj->raiseError("75", 75);
+$obj->raiseError("13", 13);
+$obj->popExpect();
+
+print "subtest 6\n";
+$obj->expectError();
+$obj->raiseError("123", 123);
+$obj->raiseError("456", 456);
+$obj->raiseError("789", 789);
+$obj->popExpect();
+
+print "subtest 7\n";
+$obj->expectError("syntax error");
+$obj->raiseError("type mismatch");
+$obj->raiseError("syntax error");
+$obj->popExpect();
+
+?>
+--EXPECT--
+subtest 1
+error: 2
+subtest 2
+error: 3
+subtest 3
+subtest 4
+error: 0
+error: 6
+error: error
+subtest 5
+subtest 6
+subtest 7
+error: type mismatch