Development

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

You must first sign up to be able to contribute.

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

Revision 19531, 2.6 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(7);
14
15 require_once(dirname(__FILE__).'/../../../lib/util/sfToolkit.class.php');
16 $file = sys_get_temp_dir().DIRECTORY_SEPARATOR.'sf_log_file.txt';
17 if (file_exists($file))
18 {
19   unlink($file);
20 }
21
22 $dispatcher = new sfEventDispatcher();
23
24 // ->initialize()
25 $t->diag('->initialize()');
26 try
27 {
28   $logger = new sfFileLogger($dispatcher);
29   $t->fail('->initialize() parameters must contains a "file" parameter');
30 }
31 catch (sfConfigurationException $e)
32 {
33   $t->pass('->initialize() parameters must contains a "file" parameter');
34 }
35
36 // ->log()
37 $t->diag('->log()');
38 $logger = new sfFileLogger($dispatcher, array('file' => $file));
39 $logger->log('foo');
40 $lines = explode("\n", file_get_contents($file));
41 $t->like($lines[0], '/foo/', '->log() logs a message to the file');
42 $logger->log('bar');
43 $lines = explode("\n", file_get_contents($file));
44 $t->like($lines[1], '/bar/', '->log() logs a message to the file');
45
46 class TestLogger extends sfFileLogger
47 {
48   public function getTimeFormat()
49   {
50     return $this->timeFormat;
51   }
52
53   protected function getPriority($priority)
54   {
55     return '*'.$priority.'*';
56   }
57 }
58
59 // option: format
60 $t->diag('option: format');
61 unlink($file);
62 $logger = new TestLogger($dispatcher, array('file' => $file));
63 $logger->log('foo');
64 $t->is(file_get_contents($file), strftime($logger->getTimeFormat()).' symfony [*6*] foo'.PHP_EOL, '->initialize() can take a format option');
65
66 unlink($file);
67 $logger = new TestLogger($dispatcher, array('file' => $file, 'format' => '%message%'));
68 $logger->log('foo');
69 $t->is(file_get_contents($file), 'foo', '->initialize() can take a format option');
70
71 // option: time_format
72 $t->diag('option: time_format');
73 unlink($file);
74 $logger = new TestLogger($dispatcher, array('file' => $file, 'time_format' => '%Y %m %d'));
75 $logger->log('foo');
76 $t->is(file_get_contents($file), strftime($logger->getTimeFormat()).' symfony [*6*] foo'.PHP_EOL, '->initialize() can take a format option');
77
78 // option: type
79 $t->diag('option: type');
80 unlink($file);
81 $logger = new TestLogger($dispatcher, array('file' => $file, 'type' => 'foo'));
82 $logger->log('foo');
83 $t->is(file_get_contents($file), strftime($logger->getTimeFormat()).' foo [*6*] foo'.PHP_EOL, '->initialize() can take a format option');
84
85 // ->shutdown()
86 $t->diag('->shutdown()');
87 $logger->shutdown();
88
89 unlink($file);
90
Note: See TracBrowser for help on using the browser.