From 479b2ca44e36c206d1dcbf6ba114b94d2a9948df Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel Date: Thu, 11 Feb 2010 12:11:48 +0100 Subject: [PATCH] Complete exception testing. --- .../test/Horde/Exception/ExceptionTest.php | 48 ++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/framework/Exception/test/Horde/Exception/ExceptionTest.php b/framework/Exception/test/Horde/Exception/ExceptionTest.php index 0e4c84cec..ae0dcf6e4 100644 --- a/framework/Exception/test/Horde/Exception/ExceptionTest.php +++ b/framework/Exception/test/Horde/Exception/ExceptionTest.php @@ -15,8 +15,10 @@ * Require the tested classes. */ require_once 'Horde/Exception.php'; -require_once 'Horde/Exception/Prior.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'; /** * Test for the Horde_Exception:: class. @@ -35,18 +37,56 @@ require_once 'Horde/Exception/LastError.php'; class Horde_Exception_ExceptionTest extends PHPUnit_Framework_TestCase { + // Basic Exception Testing + public function testEmptyConstructionYieldsEmptyMessage() { - $e = new Horde_Exception_Prior(); + $e = new Horde_Exception(); $this->assertSame('', $e->getMessage()); } public function testEmptyConstructionYieldsCodeZero() { - $e = new Horde_Exception_Prior(); + $e = new Horde_Exception(); $this->assertSame(0, $e->getCode()); } + public function testMethodGetpreviousYieldsPreviousException() + { + $e = new Horde_Exception(null, null, new Exception('previous')); + $this->assertEquals('previous', $e->getPrevious()->getMessage()); + } + + public function testMethodTostringYieldsExceptionDescription() + { + $e = new Horde_Exception(); + $this->assertContains('exception \'Horde_Exception\'', (string) $e); + } + + public function testMethodTostringContainsDescriptionOfPreviousException() + { + $e = new Horde_Exception(null, null, new Exception('previous')); + $this->assertContains('Next exception \'Horde_Exception\'', (string) $e); + } + + // NotFound Exception Testing + + public function testEmptyConstructionYieldsNotFoundMessage() + { + $e = new Horde_Exception_NotFound(); + $this->assertSame('Not Found', $e->getMessage()); + } + + // Basic Exception Testing + + public function testEmptyConstructionYieldsPermissionDeniedMessage() + { + $e = new Horde_Exception_PermissionDenied(); + $this->assertSame('Permission Denied', $e->getMessage()); + } + + // Prior Exception Testing + public function testConstructionWithPearErrorYieldsMessageFromPearError() { require_once dirname(__FILE__) . '/Stub/PearError.php'; @@ -63,6 +103,8 @@ class Horde_Exception_ExceptionTest extends PHPUnit_Framework_TestCase $this->assertSame(666, $e->getCode()); } + // LastError Exception Testing + public function testConstructionWithGetlasterrorarrayYieldsMessageFromArray() { $e = new Horde_Exception_LastError(null, $this->_getLastError()); -- 2.11.0