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