/usr/share/php/tests/Horde_Exception/Horde/Exception/ExceptionTest.php is in php-horde-exception 2.0.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | <?php
/**
* Copyright 2009-2013 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @package Exception
* @author Gunnar Wrobel <wrobel@pardus.de>
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
*/
/**
* Tests for the Horde_Exception class.
*
* @category Horde
* @package Exception
* @author Gunnar Wrobel <wrobel@pardus.de>
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
*/
class Horde_Exception_ExceptionTest extends PHPUnit_Framework_TestCase
{
// Basic Exception Testing
public function testEmptyConstructionYieldsEmptyMessage()
{
$e = new Horde_Exception();
$this->assertSame('', $e->getMessage());
}
public function testEmptyConstructionYieldsCodeZero()
{
$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()
{
setlocale(LC_MESSAGES, 'C');
$e = new Horde_Exception_NotFound();
$this->assertSame('Not Found', $e->getMessage());
}
// Basic Exception Testing
public function testEmptyConstructionYieldsPermissionDeniedMessage()
{
setlocale(LC_MESSAGES, 'C');
$e = new Horde_Exception_PermissionDenied();
$this->assertSame('Permission Denied', $e->getMessage());
}
// Prior Exception Testing
public function testConstructionWithPearErrorYieldsMessageFromPearError()
{
require_once __DIR__ . '/Stub/PearError.php';
$p = new Horde_Exception_Stub_PearError('pear');
$e = new Horde_Exception_Wrapped($p);
$this->assertSame('pear', $e->getMessage());
}
public function testConstructionWithPearErrorYieldsCodeFromPearError()
{
require_once __DIR__ . '/Stub/PearError.php';
$p = new Horde_Exception_Stub_PearError('pear', 666);
$e = new Horde_Exception_Wrapped($p);
$this->assertSame(666, $e->getCode());
}
// LastError Exception Testing
public function testConstructionOfLastErrorYieldsStandardException()
{
$e = new Horde_Exception_LastError();
$this->assertSame('', $e->getMessage());
}
public function testConstructionWithGetlasterrorarrayYieldsMessageFromArray()
{
$e = new Horde_Exception_LastError(null, $this->_getLastError());
$this->assertSame('get_last_error', $e->getMessage());
}
public function testConstructionWithGetlasterrorarrayYieldsCodeFromArray()
{
$e = new Horde_Exception_LastError(null, $this->_getLastError());
$this->assertSame(666, $e->getCode());
}
public function testConstructionWithGetlasterrorarrayYieldsFileFromArray()
{
$e = new Horde_Exception_LastError(null, $this->_getLastError());
$this->assertSame('/some/file.php', $e->getFile());
}
public function testConstructionWithGetlasterrorarrayYieldsLineFromArray()
{
$e = new Horde_Exception_LastError(null, $this->_getLastError());
$this->assertSame(99, $e->getLine());
}
public function testConstructionWithGetlasterrorarrayConcatenatesMessagesFromConstructorAndErrorarray()
{
$e = new Horde_Exception_LastError('An error occurred: ', $this->_getLastError());
$this->assertSame('An error occurred: get_last_error', $e->getMessage());
}
public function testCatchingAndConvertingPearErrors()
{
$this->_loadPear();
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->details
);
}
}
public function testStringUserinfo()
{
$this->_loadPear();
try {
Horde_Exception_Pear::catchError(
new PEAR_Error('An error occurred.', null, null, null, 'userinfo')
);
} catch (Horde_Exception_Pear $e) {
$this->assertContains('userinfo', $e->details);
}
}
public function testArrayUserinfo()
{
$this->_loadPear();
try {
Horde_Exception_Pear::catchError(
new PEAR_Error('An error occurred.', null, null, null, array('userinfo'))
);
} catch (Horde_Exception_Pear $e) {
$this->assertContains('[0] => userinfo', $e->details);
}
}
private function _getLastError()
{
return array(
'message' => 'get_last_error',
'type' => 666,
'file' => '/some/file.php',
'line' => 99
);
}
private function _loadPear()
{
@require_once 'PEAR.php';
if (!class_exists('PEAR_Error')) {
$this->markTestSkipped('PEAR_Error is missing!');
}
}
}
|