OSDN Git Service

- moved plugin related Test file to "Plugin" dir.
[ethna/ethna.git] / test / Plugin / Logwriter / Ethna_Plugin_Logwriter_File_Test.php
1 <?php
2 /**
3  *  Ethna_Plugin_Logwriter_File_Test.php
4  */
5
6 /**
7  *  Ethna_Plugin_Logwriter_Fileクラスのテストケース
8  *
9  *  @access public
10  */
11 class Ethna_Plugin_Logwriter_File_Test extends Ethna_UnitTestBase
12 {
13     function testLogwriterFile()
14     {
15         $ctl =& Ethna_Controller::getInstance();
16         $plugin =& $ctl->getPlugin();
17         $lw = $plugin->getPlugin('Logwriter', 'File');
18
19         $option = array(
20                         'ident'    => 'hoge',
21                         'facility' => 'mail',
22                         'file'     => 'logfile',
23                         'mode'     => '0666',
24                         );
25         $lw->setOption($option);
26
27         $level = LOG_WARNING;
28         $message = 'comment';
29         $lw->begin();
30         $_before_size = filesize($option['file']);
31         $this->assertTrue(file_exists($option['file']));
32         $lw->log($level, $message);
33         $lw->end();
34         clearstatcache();
35         $_after_size = filesize($option['file']);
36         // ログを出力したファイルのサイズが大きくなったことを確認
37         $this->assertTrue($_before_size < $_after_size);
38
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:'), '/')
43                             .'[0-5][0-9] '
44                             .preg_quote($option['ident'].'('
45                                         .$lw->_getLogLevelName($level).'): '
46                                         .$message)
47                             .'/', trim($file[$line_count - 1])));
48
49
50         $option = array(
51                         'pid'      => true,
52                         'ident'    => 'hoge',
53                         'facility' => 'mail',
54                         'file'     => 'logfile',
55                         'mode'     => '0666',
56                         );
57         $lw->setOption($option);
58
59         $level = LOG_WARNING;
60         $message = 'comment';
61         $lw->begin();
62         $_before_size = filesize($option['file']);
63         $this->assertTrue(file_exists($option['file']));
64         $lw->log($level, $message);
65         $lw->end();
66         clearstatcache();
67         $_after_size = filesize($option['file']);
68         // ログを出力したファイルのサイズが大きくなったことを確認
69         $this->assertTrue($_before_size < $_after_size);
70
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:'), '/')
75                             .'[0-5][0-9] '
76                             .preg_quote($option['ident'].'['.getmypid().']('
77                                         .$lw->_getLogLevelName($level).'): '
78                                         .$message)
79                             .'/', trim($file[$line_count - 1])));
80
81         unlink($option['file']);
82
83     }
84 }
85 ?>