|
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\AbstractLineParser; |
|
13
|
|
|
|
|
14
|
|
|
class AbstractLineParserTest extends \PHPUnit_Framework_TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Creates and returns instance of AbstractLineParser mock. |
|
18
|
|
|
* |
|
19
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|AbstractLineParser |
|
20
|
|
|
*/ |
|
21
|
|
|
protected function getParser() |
|
22
|
|
|
{ |
|
23
|
|
|
$mock = $this->getMock( |
|
24
|
|
|
'\\MVar\\Apache2LogParser\\AbstractLineParser', |
|
25
|
|
|
['prepareParsedData', 'getPattern'] |
|
26
|
|
|
); |
|
27
|
|
|
|
|
28
|
|
|
return $mock; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Test for parseLine() in case of exception when passed incorrect argument. |
|
33
|
|
|
* |
|
34
|
|
|
* @expectedException \MVar\Apache2LogParser\Exception\ParserException |
|
35
|
|
|
* @expectedExceptionMessage must be a string |
|
36
|
|
|
*/ |
|
37
|
|
|
public function testParseLineExceptionArgument() |
|
38
|
|
|
{ |
|
39
|
|
|
$parser = $this->getParser(); |
|
40
|
|
|
$parser->parseLine([123, 456]); |
|
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Test for parseLine() in case of exception when matcher fails. |
|
45
|
|
|
* |
|
46
|
|
|
* @expectedException \MVar\Apache2LogParser\Exception\ParserException |
|
47
|
|
|
* @expectedExceptionMessage Matcher failure |
|
48
|
|
|
*/ |
|
49
|
|
|
public function testParseLineExceptionMatcherFailure() |
|
50
|
|
|
{ |
|
51
|
|
|
$parser = $this->getParser(); |
|
52
|
|
|
$parser->expects($this->once())->method('getPattern')->willReturn('invalid_regexp_pattern'); |
|
53
|
|
|
|
|
54
|
|
|
$parser->parseLine('test string'); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Test for parseLine() in case of exception when no matches were found. |
|
59
|
|
|
* |
|
60
|
|
|
* @expectedException \MVar\Apache2LogParser\Exception\NoMatchesException |
|
61
|
|
|
* @expectedExceptionMessage line does not match |
|
62
|
|
|
*/ |
|
63
|
|
|
public function testParseLineExceptionNoMatches() |
|
64
|
|
|
{ |
|
65
|
|
|
$parser = $this->getParser(); |
|
66
|
|
|
$parser->expects($this->once())->method('getPattern')->willReturn('/\d+/'); |
|
67
|
|
|
|
|
68
|
|
|
$parser->parseLine('test string'); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Test for parseLine(). |
|
73
|
|
|
*/ |
|
74
|
|
|
public function testParseLine() |
|
75
|
|
|
{ |
|
76
|
|
|
$parser = $this->getParser(); |
|
77
|
|
|
$parser->expects($this->once())->method('getPattern')->willReturn('/.*/'); |
|
78
|
|
|
|
|
79
|
|
|
$parser->parseLine('test string'); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: