cvs: php4 /pear PEAR.php /pear/tests pear_error.phpt pear_error2.phpt pear_error3.phpt pear_error4.phpt

From: Date: Sun, 04 Nov 2001 09:07:17 +0000
Subject: cvs: php4 /pear PEAR.php /pear/tests pear_error.phpt pear_error2.phpt pear_error3.phpt pear_error4.phpt
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-1253@lists.php.net to get a copy of this message
ssb Sun Nov 4 04:07:17 2001 EDT Added files: /php4/pear/tests pear_error4.phpt Modified files: /php4/pear PEAR.php /php4/pear/tests pear_error.phpt pear_error2.phpt pear_error3.phpt Log: * expectError() now accepts "*" as a catch-all * updated tests Index: php4/pear/PEAR.php diff -u php4/pear/PEAR.php:1.26 php4/pear/PEAR.php:1.27 --- php4/pear/PEAR.php:1.26 Wed Oct 31 00:48:16 2001 +++ php4/pear/PEAR.php Sun Nov 4 04:07:16 2001 @@ -19,7 +19,7 @@ // | | // +----------------------------------------------------------------------+ // -// $Id: PEAR.php,v 1.26 2001/10/31 05:48:16 ssb Exp $ +// $Id: PEAR.php,v 1.27 2001/11/04 09:07:16 ssb Exp $ // define('PEAR_ERROR_RETURN', 1); @@ -286,7 +286,7 @@ * * @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 @@ $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) { Index: php4/pear/tests/pear_error.phpt diff -u php4/pear/tests/pear_error.phpt:1.16 php4/pear/tests/pear_error.phpt:1.17 --- php4/pear/tests/pear_error.phpt:1.16 Wed Oct 31 00:52:41 2001 +++ php4/pear/tests/pear_error.phpt Sun Nov 4 04:07:16 2001 @@ -1,5 +1,5 @@ --TEST-- -PEAR_Error test +PEAR_Error: basic test --SKIPIF-- --FILE-- <?php // -*- PHP -*- @@ -8,7 +8,7 @@ // 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 @@ $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=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 Index: php4/pear/tests/pear_error2.phpt diff -u php4/pear/tests/pear_error2.phpt:1.1 php4/pear/tests/pear_error2.phpt:1.2 --- php4/pear/tests/pear_error2.phpt:1.1 Fri Sep 8 22:39:56 2000 +++ php4/pear/tests/pear_error2.phpt Sun Nov 4 04:07:17 2001 @@ -1,5 +1,5 @@ --TEST-- -PEAR_Error in die mode +PEAR_Error: die mode --SKIPIF-- --FILE-- <?php // -*- C++ -*- @@ -9,9 +9,9 @@ // - 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); Index: php4/pear/tests/pear_error3.phpt diff -u php4/pear/tests/pear_error3.phpt:1.1 php4/pear/tests/pear_error3.phpt:1.2 --- php4/pear/tests/pear_error3.phpt:1.1 Mon Jan 29 19:55:27 2001 +++ php4/pear/tests/pear_error3.phpt Sun Nov 4 04:07:17 2001 @@ -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) { Index: php4/pear/tests/pear_error4.phpt +++ php4/pear/tests/pear_error4.phpt --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

« previous php.pear.cvs (#1253) next »