|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* (c) Mantas Varatiejus <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace MVar\Apache2LogParser\Tests; |
|
11
|
|
|
|
|
12
|
|
|
use MVar\Apache2LogParser\ErrorLogParser; |
|
13
|
|
|
|
|
14
|
|
|
class ErrorLogParserTest extends \PHPUnit_Framework_TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* {@inheritdoc} |
|
18
|
|
|
*/ |
|
19
|
|
|
public static function setUpBeforeClass() |
|
20
|
|
|
{ |
|
21
|
|
|
date_default_timezone_set('UTC'); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Test for parseLine(). |
|
26
|
|
|
* |
|
27
|
|
|
* @param string $line |
|
28
|
|
|
* @param array $expectedResult |
|
29
|
|
|
* |
|
30
|
|
|
* @dataProvider getTestParseLineData() |
|
31
|
|
|
*/ |
|
32
|
|
|
public function testParseLine($line, array $expectedResult) |
|
33
|
|
|
{ |
|
34
|
|
|
$parser = new ErrorLogParser(); |
|
35
|
|
|
$result = $parser->parseLine($line); |
|
36
|
|
|
|
|
37
|
|
|
$this->assertEquals($expectedResult, $result); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Data provider for testParseLine(). |
|
42
|
|
|
* |
|
43
|
|
|
* @return array[] |
|
44
|
|
|
*/ |
|
45
|
|
|
public function getTestParseLineData() |
|
46
|
|
|
{ |
|
47
|
|
|
return [ |
|
48
|
|
|
[ |
|
49
|
|
|
'[Sat Dec 14 21:07:07 2013] [error] [client 127.0.0.1] ' . |
|
50
|
|
|
'File does not exist: /home/user/project/skin/base', |
|
51
|
|
|
[ |
|
52
|
|
|
'time' => 'Sat Dec 14 21:07:07 2013', |
|
53
|
|
|
'error_level' => 'error', |
|
54
|
|
|
'client_ip' => '127.0.0.1', |
|
55
|
|
|
'message' => 'File does not exist: /home/user/project/skin/base', |
|
56
|
|
|
], |
|
57
|
|
|
], |
|
58
|
|
|
[ |
|
59
|
|
|
'[Sat Dec 21 17:33:53 2013] [notice] Apache/2.2.22 (Ubuntu) PHP/5.3.10-1ubuntu3.9 with ' . |
|
60
|
|
|
'Suhosin-Patch mod_ssl/2.2.22 OpenSSL/1.0.1 configured -- resuming normal operations', |
|
61
|
|
|
[ |
|
62
|
|
|
'time' => 'Sat Dec 21 17:33:53 2013', |
|
63
|
|
|
'error_level' => 'notice', |
|
64
|
|
|
'message' => 'Apache/2.2.22 (Ubuntu) PHP/5.3.10-1ubuntu3.9 with ' . |
|
65
|
|
|
'Suhosin-Patch mod_ssl/2.2.22 OpenSSL/1.0.1 configured -- resuming normal operations', |
|
66
|
|
|
], |
|
67
|
|
|
], |
|
68
|
|
|
[ |
|
69
|
|
|
'[Sat Dec 28 16:55:56 2013] [error] [client 192.168.5.1] File does not exist: ' . |
|
70
|
|
|
'/var/www/favicon.ico, referer: http://server.vm/', |
|
71
|
|
|
[ |
|
72
|
|
|
'time' => 'Sat Dec 28 16:55:56 2013', |
|
73
|
|
|
'error_level' => 'error', |
|
74
|
|
|
'client_ip' => '192.168.5.1', |
|
75
|
|
|
'message' => 'File does not exist: /var/www/favicon.ico', |
|
76
|
|
|
'referer' => 'http://server.vm/', |
|
77
|
|
|
], |
|
78
|
|
|
], |
|
79
|
|
|
]; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|