3 * Ethna_Plugin_Logwriter_File_Test.php
7 * Ethna_Plugin_Logwriter_Fileクラスのテストケース
11 class Ethna_Plugin_Logwriter_File_Test extends Ethna_UnitTestBase
13 function testLogwriterFile()
15 $ctl =& Ethna_Controller::getInstance();
16 $plugin =& $ctl->getPlugin();
17 $lw = $plugin->getPlugin('Logwriter', 'File');
25 $lw->setOption($option);
30 $_before_size = filesize($option['file']);
31 $this->assertTrue(file_exists($option['file']));
32 $lw->log($level, $message);
35 $_after_size = filesize($option['file']);
36 // ログを出力したファイルのサイズが大きくなったことを確認
37 $this->assertTrue($_before_size < $_after_size);
39 $file = file($option['file']);
40 $line_count = count($file); // 最後に追記した行番号
41 // 年月日時分の一致、秒のフォーマット、ID・ログレベル・メッセージの一致を確認
42 $this->assertTrue(preg_match('/^'.preg_quote(strftime('%Y/%m/%d %H:%M:'), '/')
44 .preg_quote($option['ident'].'('
45 .$lw->_getLogLevelName($level).'): '
47 .'/', trim($file[$line_count - 1])));
57 $lw->setOption($option);
62 $_before_size = filesize($option['file']);
63 $this->assertTrue(file_exists($option['file']));
64 $lw->log($level, $message);
67 $_after_size = filesize($option['file']);
68 // ログを出力したファイルのサイズが大きくなったことを確認
69 $this->assertTrue($_before_size < $_after_size);
71 $file = file($option['file']);
72 $line_count = count($file); // 最後に追記した行番号
73 // 年月日時分の一致、秒のフォーマット、ID・PID・ログレベル・メッセージの一致を確認
74 $this->assertTrue(preg_match('/^'.preg_quote(strftime('%Y/%m/%d %H:%M:'), '/')
76 .preg_quote($option['ident'].'['.getmypid().']('
77 .$lw->_getLogLevelName($level).'): '
79 .'/', trim($file[$line_count - 1])));
81 unlink($option['file']);