/usr/share/php/tests/Horde_Log/Horde/Log/LogTest.php is in php-horde-log 2.1.0-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 | <?php
/**
* Horde Log package
*
* This package is based on Zend_Log from the Zend Framework
* (http://framework.zend.com). Both that package and this
* one were written by Mike Naberezny and Chuck Hagenbuch.
*
* @author Mike Naberezny <mike@maintainable.com>
* @author Chuck Hagenbuch <chuck@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/bsd BSD
* @package Log
* @subpackage UnitTests
*/
/**
* @author Mike Naberezny <mike@maintainable.com>
* @author Chuck Hagenbuch <chuck@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/bsd BSD
* @package Log
* @subpackage UnitTests
*/
class Horde_Log_LogTest extends PHPUnit_Framework_TestCase
{
public function setUp()
{
date_default_timezone_set('America/New_York');
$this->log = fopen('php://memory', 'a');
$this->handler = new Horde_Log_Handler_Stream($this->log);
}
// Handlers
public function testHandlerCanBeAddedWithConstructor()
{
$logger = new Horde_Log_Logger($this->handler);
$logger->log($message = 'message-to-long', Horde_Log::INFO);
rewind($this->log);
$this->assertContains($message, stream_get_contents($this->log));
}
public function testaddHandler()
{
$logger = new Horde_Log_Logger();
$logger->addHandler($this->handler);
$logger->log($message = 'message-to-log', Horde_Log::INFO);
rewind($this->log);
$this->assertContains($message, stream_get_contents($this->log));
}
public function testaddHandlerAddsMultipleHandlers()
{
$logger = new Horde_Log_Logger();
// create handlers for two separate streams of temporary memory
$log1 = fopen('php://memory', 'a');
$handler1 = new Horde_Log_Handler_Stream($log1);
$log2 = fopen('php://memory', 'a');
$handler2 = new Horde_Log_Handler_Stream($log2);
// add the handlers
$logger->addHandler($handler1);
$logger->addHandler($handler2);
// log to both handlers
$logger->log($message = 'message-sent-to-both-logs', Horde_Log::INFO);
// verify both handlers were called by the logger
rewind($log1);
$this->assertContains($message, stream_get_contents($log1));
rewind($log2);
$this->assertContains($message, stream_get_contents($log2));
// prove the two memory streams are different
// and both handlers were indeed called
fwrite($log1, 'foo');
$this->assertNotEquals(ftell($log1), ftell($log2));
}
public function testLoggerThrowsWhenNoHandlers()
{
$logger = new Horde_Log_Logger();
try {
$logger->log('message', Horde_Log::INFO);
$this->fail();
} catch (Horde_Log_Exception $e) {
$this->assertRegexp('/no handler/i', $e->getMessage());
}
}
// Levels
public function testLogThrowsOnBadLogLevel()
{
$logger = new Horde_Log_Logger($this->handler);
try {
$logger->log('foo', 42);
$this->fail();
} catch (Exception $e) {
$this->assertInstanceOf('Horde_Log_Exception', $e);
$this->assertRegExp('/bad log level/i', $e->getMessage());
}
}
public function testLogThrough__callThrowsOnBadLogLevel()
{
$logger = new Horde_Log_Logger($this->handler);
try {
$logger->nonexistantLevel('');
$this->fail();
} catch (Exception $e) {
$this->assertInstanceOf('Horde_Log_Exception', $e);
$this->assertRegExp('/bad log level/i', $e->getMessage());
}
}
public function testAddingLevelThrowsWhenOverridingBuiltinLogLevel()
{
try {
$logger = new Horde_Log_Logger($this->handler);
$logger->addLevel('BOB', 0);
$this->fail();
} catch (Exception $e) {
$this->assertInstanceOf('Horde_Log_Exception', $e);
$this->assertRegExp('/existing log level/i', $e->getMessage());
}
}
public function testAddLogLevel()
{
$logger = new Horde_Log_Logger($this->handler);
$logger->addLevel($levelName = 'EIGHT', $level = 8);
$logger->eight($message = 'eight message');
rewind($this->log);
$logdata = stream_get_contents($this->log);
$this->assertContains($levelName, $logdata);
$this->assertContains($message, $logdata);
}
}
|