Development

/branches/1.4/test/unit/log/sfLoggerTest.php

You must first sign up to be able to contribute.

root/branches/1.4/test/unit/log/sfLoggerTest.php

Revision 19531, 3.3 kB (checked in by fabien, 4 years ago)

[1.3] removed usage of lime_output_color() in unit tests as it is now taken care of automatically by lime (closes #6695)

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
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 // ->setLogLevel() ->getLogLevel()
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 // ->initialize()
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 // ::getPriorityName()
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 // ->log()
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 // log level
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 // shortcuts
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
Note: See TracBrowser for help on using the browser.