1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the `tvi/monitor-bundle` project. |
5
|
|
|
* |
6
|
|
|
* (c) https://github.com/turnaev/monitor-bundle/graphs/contributors |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
|
|
|
|
11
|
|
|
|
12
|
|
|
namespace Tvi\MonitorBundle\Check\php\Expression; |
13
|
|
|
|
14
|
|
|
use ZendDiagnostics\Result\Failure; |
15
|
|
|
use ZendDiagnostics\Result\ResultInterface; |
16
|
|
|
use ZendDiagnostics\Result\Success; |
17
|
|
|
use ZendDiagnostics\Result\Warning; |
18
|
|
|
use Tvi\MonitorBundle\Test\Check\CheckTestCase; |
19
|
|
|
|
20
|
|
|
/** |
|
|
|
|
21
|
|
|
* @author Vladimir Turnaev <[email protected]> |
22
|
|
|
* |
23
|
|
|
* @internal |
24
|
|
|
*/ |
|
|
|
|
25
|
|
|
class Test extends CheckTestCase |
26
|
|
|
{ |
27
|
|
|
public function test_plugin() |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
$this->iterateConfTest(__DIR__.'/config.example.yml'); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
|
|
|
|
33
|
|
|
* @dataProvider checkResultProvider |
34
|
|
|
*/ |
|
|
|
|
35
|
|
|
public function test_check($warningExpression, $criticalExpression, $warningMessage, $criticalMessage, $expectedResultClass, $expectedMessage) |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
$check = new Check($warningExpression, $criticalExpression, $warningMessage, $criticalMessage); |
38
|
|
|
|
39
|
|
|
$result = $check->check(); |
40
|
|
|
|
41
|
|
|
$this->assertInstanceOf(ResultInterface::class, $result); |
42
|
|
|
$this->assertInstanceOf($expectedResultClass, $result); |
43
|
|
|
$this->assertSame($expectedMessage, $result->getMessage()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function test_check_bash() |
|
|
|
|
47
|
|
|
{ |
48
|
|
|
$this->expectException(\InvalidArgumentException::class); |
49
|
|
|
|
50
|
|
|
new Check(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function checkResultProvider() |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
return [ |
56
|
|
|
['true', 'true', null, null, Success::class, ''], |
57
|
|
|
['false', 'true', 'warning', 'fail', Warning::class, 'warning'], |
58
|
|
|
['true', 'false', 'warning', 'fail', Failure::class, 'fail'], |
59
|
|
|
['false', 'false', 'warning', 'fail', Failure::class, 'fail'], |
60
|
|
|
]; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|