| 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(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 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 86 |
$t->diag('->shutdown()'); |
|---|
| 87 |
$logger->shutdown(); |
|---|
| 88 |
|
|---|
| 89 |
unlink($file); |
|---|
| 90 |
|
|---|