1--TEST--
2DB::DB_Error
3--SKIPIF--
4<?php require_once dirname(__FILE__) . '/skipif.inc'; ?>
5--FILE--
6<?php // -*- C++ -*-
7require_once dirname(__FILE__) . '/include.inc';
8require_once 'DB.php';
9
10function test_error_handler($errno, $errmsg, $file, $line, $vars) {
11    if (defined('E_STRICT')) {
12        if ($errno & E_STRICT
13            && (error_reporting() & E_STRICT) != E_STRICT) {
14            // Ignore E_STRICT notices unless they have been turned on
15            return;
16        }
17    } else {
18        define('E_STRICT', 2048);
19    }
20    $errortype = array (
21        E_ERROR => 'Error',
22        E_WARNING => 'Warning',
23        E_PARSE => 'Parsing Error',
24        E_NOTICE => 'Notice',
25        E_CORE_ERROR => 'Core Error',
26        E_CORE_WARNING => 'Core Warning',
27        E_COMPILE_ERROR => 'Compile Error',
28        E_COMPILE_WARNING => 'Compile Warning',
29        E_USER_ERROR => 'User Error',
30        E_USER_WARNING => 'User Warning',
31        E_USER_NOTICE => 'User Notice',
32        E_STRICT => 'Strict Notice',
33    );
34    $prefix = $errortype[$errno];
35    print "\n$prefix: $errmsg in " . basename($file) . " on line XXX\n";
36}
37
38set_error_handler('test_error_handler');
39
40print "testing different error codes...\n";
41$e = new DB_Error(); print strtolower($e->toString())."\n";
42$e = new DB_Error("test error"); print strtolower($e->toString())."\n";
43$e = new DB_Error(DB_OK); print strtolower($e->toString())."\n";
44$e = new DB_Error(DB_ERROR); print strtolower($e->toString())."\n";
45$e = new DB_Error(DB_ERROR_SYNTAX); print strtolower($e->toString())."\n";
46$e = new DB_Error(DB_ERROR_DIVZERO); print strtolower($e->toString())."\n";
47
48print "testing instantiated method...\n";
49$e = new DB_Error;
50$e->DB_Error("test instantiated"); print strtolower($e->toString())."\n";
51
52print "testing different error modes...\n";
53$e = new DB_Error(DB_ERROR, PEAR_ERROR_PRINT); print strtolower($e->toString())."\n";
54$e = new DB_Error(DB_ERROR_SYNTAX, PEAR_ERROR_TRIGGER);
55
56print "testing different error serverities...\n";
57$e = new DB_Error(DB_ERROR_SYNTAX, PEAR_ERROR_TRIGGER, E_USER_NOTICE);
58$e = new DB_Error(DB_ERROR_SYNTAX, PEAR_ERROR_TRIGGER, E_USER_WARNING);
59$e = new DB_Error(DB_ERROR_SYNTAX, PEAR_ERROR_TRIGGER, E_USER_ERROR);
60?>
61--GET--
62--POST--
63--EXPECT--
64testing different error codes...
65[db_error: message="db error: unknown error" code=-1 mode=return level=notice prefix="" info=""]
66[db_error: message="db error: test error" code=-1 mode=return level=notice prefix="" info=""]
67[db_error: message="db error: no error" code=1 mode=return level=notice prefix="" info=""]
68[db_error: message="db error: unknown error" code=-1 mode=return level=notice prefix="" info=""]
69[db_error: message="db error: syntax error" code=-2 mode=return level=notice prefix="" info=""]
70[db_error: message="db error: division by zero" code=-13 mode=return level=notice prefix="" info=""]
71testing instantiated method...
72[db_error: message="db error: test instantiated" code=-1 mode=return level=notice prefix="" info=""]
73testing different error modes...
74DB Error: unknown error[db_error: message="db error: unknown error" code=-1 mode=print level=notice prefix="" info=""]
75
76User Notice: DB Error: syntax error in PEAR.php on line XXX
77testing different error serverities...
78
79User Notice: DB Error: syntax error in PEAR.php on line XXX
80
81User Warning: DB Error: syntax error in PEAR.php on line XXX
82
83User Error: DB Error: syntax error in PEAR.php on line XXX
84