|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jalle19\StatusManager\Test\Configuration; |
|
4
|
|
|
|
|
5
|
|
|
use Jalle19\StatusManager\Configuration\Validator; |
|
6
|
|
|
use Jalle19\StatusManager\Exception\InvalidConfigurationException; |
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class ValidatorTest |
|
11
|
|
|
* @package Jalle19\StatusManager\Test\Configuration |
|
12
|
|
|
* @copyright Copyright © Sam Stenvall 2016- |
|
13
|
|
|
* @license https://www.gnu.org/licenses/gpl.html The GNU General Public License v2.0 |
|
14
|
|
|
*/ |
|
15
|
|
|
class ValidatorTest extends TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
use BasicConfigurationTrait; |
|
19
|
|
|
|
|
20
|
|
|
public function testMandatoryValues() |
|
21
|
|
|
{ |
|
22
|
|
|
$this->expectExceptionMessageMatches("*Mandatory*"); |
|
23
|
|
|
$this->expectException(InvalidConfigurationException::class); |
|
24
|
|
|
$configuration = [ |
|
25
|
|
|
|
|
26
|
|
|
]; |
|
27
|
|
|
|
|
28
|
|
|
$validator = new Validator($configuration); |
|
29
|
|
|
$validator->validate(); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
public function testDatabasePath() |
|
34
|
|
|
{ |
|
35
|
|
|
$this->expectExceptionMessageMatches("*The database path*"); |
|
36
|
|
|
$this->expectException(InvalidConfigurationException::class); |
|
37
|
|
|
$configuration = $this->getBaseConfiguration(); |
|
38
|
|
|
$configuration['database_path'] = '/tmp/does/not/exist'; |
|
39
|
|
|
|
|
40
|
|
|
$validator = new Validator($configuration); |
|
41
|
|
|
$validator->validate(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
public function testLogPath() |
|
46
|
|
|
{ |
|
47
|
|
|
$this->expectExceptionMessageMatches("*The log path*"); |
|
48
|
|
|
$this->expectException(InvalidConfigurationException::class); |
|
49
|
|
|
$configuration = $this->getBaseConfiguration(); |
|
50
|
|
|
$configuration['log_path'] = '/some/other/path'; |
|
51
|
|
|
|
|
52
|
|
|
$validator = new Validator($configuration); |
|
53
|
|
|
$validator->validate(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @dataProvider updateIntervalProvider |
|
59
|
|
|
* |
|
60
|
|
|
* @param mixed $updateInterval |
|
61
|
|
|
* |
|
62
|
|
|
* |
|
63
|
|
|
* |
|
64
|
|
|
*/ |
|
65
|
|
|
public function testUpdateInterval($updateInterval) |
|
66
|
|
|
{ |
|
67
|
|
|
$this->expectExceptionMessageMatches("*Update interval cannot*"); |
|
68
|
|
|
$this->expectException(InvalidConfigurationException::class); |
|
69
|
|
|
$configuration = $this->getBaseConfiguration(); |
|
70
|
|
|
$configuration['update_interval'] = $updateInterval; |
|
71
|
|
|
|
|
72
|
|
|
$validator = new Validator($configuration); |
|
73
|
|
|
$validator->validate(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
public function testListenPorts() |
|
78
|
|
|
{ |
|
79
|
|
|
$this->expectExceptionMessage("listen_port and http_listen_port cannot be equal"); |
|
80
|
|
|
$this->expectException(InvalidConfigurationException::class); |
|
81
|
|
|
$configuration = $this->getBaseConfiguration(); |
|
82
|
|
|
$configuration['http_listen_port'] = $configuration['listen_port']; |
|
83
|
|
|
|
|
84
|
|
|
$validator = new Validator($configuration); |
|
85
|
|
|
$validator->validate(); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @dataProvider listenPortProvider |
|
91
|
|
|
* |
|
92
|
|
|
* @param int $listenPort |
|
93
|
|
|
* |
|
94
|
|
|
* |
|
95
|
|
|
* |
|
96
|
|
|
*/ |
|
97
|
|
|
public function testListenPort($listenPort) |
|
98
|
|
|
{ |
|
99
|
|
|
$this->expectExceptionMessageMatches("*Listen port must be between*"); |
|
100
|
|
|
$this->expectException(InvalidConfigurationException::class); |
|
101
|
|
|
$configuration = $this->getBaseConfiguration(); |
|
102
|
|
|
$configuration['listen_port'] = $listenPort; |
|
103
|
|
|
|
|
104
|
|
|
$validator = new Validator($configuration); |
|
105
|
|
|
$validator->validate(); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @return array |
|
111
|
|
|
*/ |
|
112
|
|
|
public function updateIntervalProvider() |
|
113
|
|
|
{ |
|
114
|
|
|
return [ |
|
115
|
|
|
[0], |
|
116
|
|
|
[0.5], |
|
117
|
|
|
[0.99], |
|
118
|
|
|
]; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @return array |
|
124
|
|
|
*/ |
|
125
|
|
|
public function listenPortProvider() |
|
126
|
|
|
{ |
|
127
|
|
|
return [ |
|
128
|
|
|
[-1], |
|
129
|
|
|
[0], |
|
130
|
|
|
[65536], |
|
131
|
|
|
[100000], |
|
132
|
|
|
]; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
} |
|
136
|
|
|
|