public function __construct(PEAR_Error $error)
{
parent::__construct(
- $error->getMessage() . $this->_getPearTrace(),
+ $error->getMessage() . $this->_getPearTrace($error),
$error->getCode()
);
}
{
$backtrace = $error->getBacktrace();
if (!empty($backtrace)) {
- $pear_error .= "\n\n" . 'PEAR Error:' . "\n";
+ $pear_error = "\n\n" . 'PEAR Error:' . "\n";
foreach ($backtrace as $frame) {
- $pear_error .= ' ' . $frame['class'] . '->'
- . $frame['function'] . ' ' . $frame['file']
- . ':' . $frame['line'] . "\n";
+ $pear_error .= ' '
+ . (isset($frame['class']) ? $frame['class'] : 'unkown')
+ . (isset($frame['type']) ? $frame['type'] : 'unkown')
+ . (isset($frame['function']) ? $frame['function'] : 'unkown') . ' '
+ . (isset($frame['file']) ? $frame['file'] : 'unkown') . ':'
+ . (isset($frame['line']) ? $frame['line'] : 'unkown') . "\n";
}
$pear_error .= "\n";
return $pear_error;
--- /dev/null
+<?php
+/**
+ * Setup autoloading for the tests.
+ *
+ * PHP version 5
+ *
+ * Copyright 2009-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Horde
+ * @package Exception
+ * @subpackage UnitTests
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Exception
+ */
+
+require_once 'Horde/Test/Autoload.php';
+
+/** Catch strict standards */
+error_reporting(E_ALL | E_STRICT);
/**
* Require the tested classes.
*/
-require_once 'Horde/Exception.php';
-require_once 'Horde/Exception/LastError.php';
-require_once 'Horde/Exception/NotFound.php';
-require_once 'Horde/Exception/PermissionDenied.php';
-require_once 'Horde/Exception/Prior.php';
+require_once 'Autoload.php';
/**
* Test for the Horde_Exception:: class.
$this->assertSame('An error occurred: get_last_error', $e->getMessage());
}
+ public function testCatchingAndConvertingPearErrors()
+ {
+ @require_once 'PEAR.php';
+ if (!class_exists('PEAR_Error')) {
+ $this->markTestSkipped('PEAR_Error is missing!');
+ }
+ try {
+ Horde_Exception_Pear::catchError(new PEAR_Error('An error occurred.'));
+ } catch (Horde_Exception_Pear $e) {
+ $this->assertContains(
+ 'Horde_Exception_ExceptionTest->testCatchingAndConvertingPearErrors unkown:unkown',
+ $e->getMessage()
+ );
+ }
+ }
+
private function _getLastError()
{
return array(