| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); |
|---|
| 12 |
|
|---|
| 13 |
$t = new lime_test(136); |
|---|
| 14 |
|
|---|
| 15 |
class myLogger extends sfLogger |
|---|
| 16 |
{ |
|---|
| 17 |
public $log = ''; |
|---|
| 18 |
|
|---|
| 19 |
protected function doLog($message, $priority) |
|---|
| 20 |
{ |
|---|
| 21 |
$this->log .= $message; |
|---|
| 22 |
} |
|---|
| 23 |
} |
|---|
| 24 |
|
|---|
| 25 |
class notaLogger |
|---|
| 26 |
{ |
|---|
| 27 |
} |
|---|
| 28 |
|
|---|
| 29 |
$dispatcher = new sfEventDispatcher(); |
|---|
| 30 |
$logger = new myLogger($dispatcher, array('log_dir_name' => '/tmp')); |
|---|
| 31 |
|
|---|
| 32 |
$options = $logger->getOptions(); |
|---|
| 33 |
$t->is($options['log_dir_name'], '/tmp', '->getOptions() returns the options for the logger instance'); |
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
$t->diag('->setLogLevel() ->getLogLevel()'); |
|---|
| 37 |
$t->is($logger->getLogLevel(), sfLogger::INFO, '->getLogLevel() gets the current log level'); |
|---|
| 38 |
$logger->setLogLevel(sfLogger::WARNING); |
|---|
| 39 |
$t->is($logger->getLogLevel(), sfLogger::WARNING, '->setLogLevel() sets the log level'); |
|---|
| 40 |
$logger->setLogLevel('err'); |
|---|
| 41 |
$t->is($logger->getLogLevel(), sfLogger::ERR, '->setLogLevel() accepts a class constant or a string as its argument'); |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
$t->diag('->initialize()'); |
|---|
| 45 |
$logger->initialize($dispatcher, array('level' => sfLogger::ERR)); |
|---|
| 46 |
$t->is($logger->getLogLevel(), sfLogger::ERR, '->initialize() takes an array of options as its second argument'); |
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
$t->diag('::getPriorityName()'); |
|---|
| 50 |
$t->is(sfLogger::getPriorityName(sfLogger::INFO), 'info', '::getPriorityName() returns the name of a priority class constant'); |
|---|
| 51 |
try |
|---|
| 52 |
{ |
|---|
| 53 |
sfLogger::getPriorityName(100); |
|---|
| 54 |
$t->fail('::getPriorityName() throws an sfException if the priority constant does not exist'); |
|---|
| 55 |
} |
|---|
| 56 |
catch (sfException $e) |
|---|
| 57 |
{ |
|---|
| 58 |
$t->pass('::getPriorityName() throws an sfException if the priority constant does not exist'); |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
$t->diag('->log()'); |
|---|
| 63 |
$logger->setLogLevel(sfLogger::DEBUG); |
|---|
| 64 |
$logger->log('message'); |
|---|
| 65 |
$t->is($logger->log, 'message', '->log() logs a message'); |
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
$t->diag('log levels'); |
|---|
| 69 |
foreach (array('emerg', 'alert', 'crit', 'err', 'warning', 'notice', 'info', 'debug') as $level) |
|---|
| 70 |
{ |
|---|
| 71 |
$levelConstant = 'sfLogger::'.strtoupper($level); |
|---|
| 72 |
|
|---|
| 73 |
foreach (array('emerg', 'alert', 'crit', 'err', 'warning', 'notice', 'info', 'debug') as $logLevel) |
|---|
| 74 |
{ |
|---|
| 75 |
$logLevelConstant = 'sfLogger::'.strtoupper($logLevel); |
|---|
| 76 |
$logger->setLogLevel(constant($logLevelConstant)); |
|---|
| 77 |
|
|---|
| 78 |
$logger->log = ''; |
|---|
| 79 |
$logger->log('foo', constant($levelConstant)); |
|---|
| 80 |
|
|---|
| 81 |
$t->is($logger->log, constant($logLevelConstant) >= constant($levelConstant), sprintf('->log() only logs if the level is >= to the defined log level (%s >= %s)', $logLevelConstant, $levelConstant)); |
|---|
| 82 |
} |
|---|
| 83 |
} |
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
$t->diag('log shortcuts'); |
|---|
| 87 |
foreach (array('emerg', 'alert', 'crit', 'err', 'warning', 'notice', 'info', 'debug') as $level) |
|---|
| 88 |
{ |
|---|
| 89 |
$levelConstant = 'sfLogger::'.strtoupper($level); |
|---|
| 90 |
|
|---|
| 91 |
foreach (array('emerg', 'alert', 'crit', 'err', 'warning', 'notice', 'info', 'debug') as $logLevel) |
|---|
| 92 |
{ |
|---|
| 93 |
$logger->setLogLevel(constant('sfLogger::'.strtoupper($logLevel))); |
|---|
| 94 |
|
|---|
| 95 |
$logger->log = ''; |
|---|
| 96 |
$logger->log('foo', constant($levelConstant)); |
|---|
| 97 |
$log1 = $logger->log; |
|---|
| 98 |
|
|---|
| 99 |
$logger->log = ''; |
|---|
| 100 |
$logger->$level('foo'); |
|---|
| 101 |
$log2 = $logger->log; |
|---|
| 102 |
|
|---|
| 103 |
$t->is($log1, $log2, sprintf('->%s($msg) is a shortcut for ->log($msg, %s)', $level, $levelConstant)); |
|---|
| 104 |
} |
|---|
| 105 |
} |
|---|
| 106 |
|
|---|