pictcode / lib / Cake / Test / Case / Log / Engine / SyslogLogTest.php @ 635eef61
履歴 | 表示 | アノテート | ダウンロード (2.603 KB)
1 | 635eef61 | spyder1211 | <?php
|
---|---|---|---|
2 | /**
|
||
3 | * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
||
4 | * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||
5 | *
|
||
6 | * Licensed under The MIT License
|
||
7 | * For full copyright and license information, please see the LICENSE.txt
|
||
8 | * Redistributions of files must retain the above copyright notice
|
||
9 | *
|
||
10 | * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||
11 | * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
||
12 | * @package Cake.Test.Case.Log.Engine
|
||
13 | * @since CakePHP(tm) v 2.4
|
||
14 | * @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||
15 | */
|
||
16 | |||
17 | App::uses('SyslogLog', 'Log/Engine'); |
||
18 | |||
19 | /**
|
||
20 | * SyslogLogTest class
|
||
21 | *
|
||
22 | * @package Cake.Test.Case.Log.Engine
|
||
23 | */
|
||
24 | class SyslogLogTest extends CakeTestCase { |
||
25 | |||
26 | /**
|
||
27 | * Tests that the connection to the logger is open with the right arguments
|
||
28 | *
|
||
29 | * @return void
|
||
30 | */
|
||
31 | public function testOpenLog() { |
||
32 | $log = $this->getMock('SyslogLog', array('_open', '_write')); |
||
33 | $log->expects($this->once())->method('_open')->with('', LOG_ODELAY, LOG_USER); |
||
34 | $log->write('debug', 'message'); |
||
35 | |||
36 | $log = $this->getMock('SyslogLog', array('_open', '_write')); |
||
37 | $log->config(array( |
||
38 | 'prefix' => 'thing', |
||
39 | 'flag' => LOG_NDELAY, |
||
40 | 'facility' => LOG_MAIL, |
||
41 | 'format' => '%s: %s' |
||
42 | )); |
||
43 | $log->expects($this->once())->method('_open') |
||
44 | ->with('thing', LOG_NDELAY, LOG_MAIL); |
||
45 | $log->write('debug', 'message'); |
||
46 | } |
||
47 | |||
48 | /**
|
||
49 | * Tests that single lines are written to syslog
|
||
50 | *
|
||
51 | * @dataProvider typesProvider
|
||
52 | * @return void
|
||
53 | */
|
||
54 | public function testWriteOneLine($type, $expected) { |
||
55 | $log = $this->getMock('SyslogLog', array('_open', '_write')); |
||
56 | $log->expects($this->once())->method('_write')->with($expected, $type . ': Foo'); |
||
57 | $log->write($type, 'Foo'); |
||
58 | } |
||
59 | |||
60 | /**
|
||
61 | * Tests that multiple lines are split and logged separately
|
||
62 | *
|
||
63 | * @return void
|
||
64 | */
|
||
65 | public function testWriteMultiLine() { |
||
66 | $log = $this->getMock('SyslogLog', array('_open', '_write')); |
||
67 | $log->expects($this->at(1))->method('_write')->with(LOG_DEBUG, 'debug: Foo'); |
||
68 | $log->expects($this->at(2))->method('_write')->with(LOG_DEBUG, 'debug: Bar'); |
||
69 | $log->expects($this->exactly(2))->method('_write'); |
||
70 | $log->write('debug', "Foo\nBar"); |
||
71 | } |
||
72 | |||
73 | /**
|
||
74 | * Data provider for the write function test
|
||
75 | *
|
||
76 | * @return array
|
||
77 | */
|
||
78 | public function typesProvider() { |
||
79 | return array( |
||
80 | array('emergency', LOG_EMERG), |
||
81 | array('alert', LOG_ALERT), |
||
82 | array('critical', LOG_CRIT), |
||
83 | array('error', LOG_ERR), |
||
84 | array('warning', LOG_WARNING), |
||
85 | array('notice', LOG_NOTICE), |
||
86 | array('info', LOG_INFO), |
||
87 | array('debug', LOG_DEBUG) |
||
88 | ); |
||
89 | } |
||
90 | |||
91 | } |