1
|
|
|
<?php |
2
|
|
|
namespace Fam\Util\UserAgentParser; |
3
|
|
|
|
4
|
|
|
use PHPUnit\Framework\TestCase; |
5
|
|
|
|
6
|
|
|
class AbstractOperatingSystemTest extends TestCase |
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* |
10
|
|
|
* @var MockOperatingSystem |
11
|
|
|
*/ |
12
|
|
|
private $subject; |
13
|
|
|
|
14
|
|
|
protected function setUp() |
15
|
|
|
{ |
16
|
|
|
parent::setUp(); |
17
|
|
|
|
18
|
|
|
$this->subject = new MockOperatingSystem(); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @test |
23
|
|
|
*/ |
24
|
|
|
public function match_WithValidValue() |
25
|
|
|
{ |
26
|
|
|
$this->subject->patterns = array( |
27
|
|
|
'/FreeBSD/i', |
28
|
|
|
); |
29
|
|
|
$this->assertTrue($this->subject->match( |
30
|
|
|
"Mozilla/5.0 (compatible; Konqueror/3.2; FreeBSD 2.6) (KHTML, like Gecko)" |
31
|
|
|
)); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @test |
36
|
|
|
*/ |
37
|
|
|
public function match_WithInvalidValue() |
38
|
|
|
{ |
39
|
|
|
$this->subject->patterns = array( |
40
|
|
|
'/FreeBSD/i', |
41
|
|
|
); |
42
|
|
|
$this->assertFalse($this->subject->match("Lynx/2.8.4rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.6c")); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @test |
47
|
|
|
*/ |
48
|
|
|
public function equals_WithValidStringValue() |
49
|
|
|
{ |
50
|
|
|
$this->subject->name = "unix"; |
51
|
|
|
$this->assertTrue($this->subject->equals("unix")); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @test |
56
|
|
|
*/ |
57
|
|
|
public function equals_WithInvalidStringValue() |
58
|
|
|
{ |
59
|
|
|
$this->subject->name = "unix"; |
60
|
|
|
$this->assertFalse($this->subject->equals("windows")); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @test |
65
|
|
|
*/ |
66
|
|
|
public function equals_WithValidOperatingSystem() |
67
|
|
|
{ |
68
|
|
|
$this->subject->name = 'unix'; |
69
|
|
|
$op = $this->getMockBuilder(OperatingSystem::class)->getMock(); |
70
|
|
|
|
71
|
|
|
$op->expects($this->once()) |
72
|
|
|
->method('getName') |
73
|
|
|
->will($this->returnValue('unix')); |
74
|
|
|
|
75
|
|
|
$this->assertTrue($this->subject->equals($op)); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @test |
80
|
|
|
* @expectedException \InvalidArgumentException |
81
|
|
|
*/ |
82
|
|
|
public function equals_ThorwsInvalidArgumentException() |
83
|
|
|
{ |
84
|
|
|
$this->subject->equals(new \stdClass()); |
|
|
|
|
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
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: