Skip to content

Commit 91eb911

Browse files
committed
Increased coverage + more tests
1 parent fc68af9 commit 91eb911

3 files changed

Lines changed: 57 additions & 10 deletions

File tree

src/UserAgentParser.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,13 @@ private function validateProduct()
9696
*/
9797
private function blacklistCheck($input)
9898
{
99-
foreach (
100-
[
101-
'mozilla',
102-
'compatible',
103-
'(',
104-
')',
105-
' ',
106-
] as $string
107-
) {
99+
foreach ([
100+
'mozilla',
101+
'compatible',
102+
'(',
103+
')',
104+
' ',
105+
] as $string) {
108106
if (stripos($input, $string) !== false) {
109107
throw new FormatException('Invalid User-agent format (`' . trim($this->product . '/' . $this->version, '/') . '`). Examples of valid User-agents: `MyCustomBot`, `MyFetcher-news`, `MyCrawler/2.1` and `MyBot-images/1.2`. See also ' . self::RFC_README);
110108
}

tests/MatchTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ public function generateDataForTest()
6161
'mybot/2.2',
6262
]
6363
],
64+
[
65+
'h3lloBot/2.1',
66+
'h3lloBot/2',
67+
[
68+
'h3lloBot',
69+
'h3lloBot/2',
70+
]
71+
],
6472
[
6573
'googlebot',
6674
false,
@@ -77,7 +85,7 @@ public function generateDataForTest()
7785
'UPPERCASE-lowercase',
7886
'UPPERCASE-lowercase/1.0',
7987
]
80-
]
88+
],
8189
];
8290
}
8391
}

tests/TruncateInvalidTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
namespace vipnytt\UserAgentParser\Tests;
3+
4+
use vipnytt\UserAgentParser;
5+
6+
/**
7+
* Class TruncateInvalidTest
8+
*
9+
* @package vipnytt\UserAgentParser\Tests
10+
*/
11+
class TruncateInvalidTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @dataProvider generateDataForTest
15+
* @param string $product
16+
* @param int|string|null $version
17+
* @expectedException \PHPUnit_Framework_Error_Warning
18+
*/
19+
public function testTruncateInvalid($product, $version)
20+
{
21+
new UserAgentParser($product, $version);
22+
}
23+
24+
/**
25+
* Generate test data
26+
* @return array
27+
*/
28+
public function generateDataForTest()
29+
{
30+
return [
31+
[
32+
'MyÇustomWebCrawler',
33+
'2.0',
34+
],
35+
[
36+
'MyCøstomWebCræwler',
37+
'2.0',
38+
],
39+
];
40+
}
41+
}

0 commit comments

Comments
 (0)