From: Gunnar Wrobel Date: Tue, 26 Oct 2010 15:19:28 +0000 (+0200) Subject: Test and fix the PEAR exception wrapper. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=2648a2e33f029d70eb835d1a7ba97d6953c3a5c7;p=horde.git Test and fix the PEAR exception wrapper. --- diff --git a/framework/Exception/lib/Horde/Exception/Pear.php b/framework/Exception/lib/Horde/Exception/Pear.php index e0d43b771..31ae8f7c7 100644 --- a/framework/Exception/lib/Horde/Exception/Pear.php +++ b/framework/Exception/lib/Horde/Exception/Pear.php @@ -34,7 +34,7 @@ class Horde_Exception_Pear extends Horde_Exception public function __construct(PEAR_Error $error) { parent::__construct( - $error->getMessage() . $this->_getPearTrace(), + $error->getMessage() . $this->_getPearTrace($error), $error->getCode() ); } @@ -50,11 +50,14 @@ class Horde_Exception_Pear extends Horde_Exception { $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; diff --git a/framework/Exception/test/Horde/Exception/Autoload.php b/framework/Exception/test/Horde/Exception/Autoload.php new file mode 100644 index 000000000..813fa4004 --- /dev/null +++ b/framework/Exception/test/Horde/Exception/Autoload.php @@ -0,0 +1,23 @@ + + * @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); diff --git a/framework/Exception/test/Horde/Exception/ExceptionTest.php b/framework/Exception/test/Horde/Exception/ExceptionTest.php index dffbdf235..7a33433cf 100644 --- a/framework/Exception/test/Horde/Exception/ExceptionTest.php +++ b/framework/Exception/test/Horde/Exception/ExceptionTest.php @@ -14,11 +14,7 @@ /** * 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. @@ -141,6 +137,22 @@ class Horde_Exception_ExceptionTest extends PHPUnit_Framework_TestCase $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(