|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the hogosha-monitor package |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (c) 2016 Guillaume Cavana |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
* |
|
11
|
|
|
* Feel free to edit as you please, and have fun. |
|
12
|
|
|
* |
|
13
|
|
|
* @author Guillaume Cavana <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace Hogosha\Monitor\Pusher; |
|
17
|
|
|
|
|
18
|
|
|
use GuzzleHttp\HandlerStack; |
|
19
|
|
|
use GuzzleHttp\Handler\MockHandler; |
|
20
|
|
|
use GuzzleHttp\Psr7\Response; |
|
21
|
|
|
use Hogosha\Monitor\Model\Result; |
|
22
|
|
|
use Hogosha\Monitor\Model\UrlInfo; |
|
23
|
|
|
use Hogosha\Monitor\Validator\Validator; |
|
24
|
|
|
use Hogosha\Sdk\Api\Client as SdkClient; |
|
25
|
|
|
use Webmozart\Console\IO\BufferedIO; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* MetricPusherTest. |
|
29
|
|
|
*/ |
|
30
|
|
|
class MetricPusherTest extends \PHPUnit_Framework_TestCase |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* pushData. |
|
34
|
|
|
*/ |
|
35
|
|
|
public function testPushData() |
|
36
|
|
|
{ |
|
37
|
|
|
$mock = new MockHandler( |
|
38
|
|
|
[ |
|
39
|
|
|
new Response(200), //Jwt response |
|
40
|
|
|
new Response(500), //metric api call response |
|
41
|
|
|
] |
|
42
|
|
|
); |
|
43
|
|
|
$handler = HandlerStack::create($mock); |
|
44
|
|
|
|
|
45
|
|
|
$options = |
|
46
|
|
|
[ |
|
47
|
|
|
'username' => null, |
|
48
|
|
|
'password' => null, |
|
49
|
|
|
'base_uri' => null, |
|
50
|
|
|
'default_resolved_incident_message' => null, |
|
51
|
|
|
'default_failed_incident_message' => null, |
|
52
|
|
|
'metric_update' => null, |
|
53
|
|
|
'incident_update' => null, |
|
54
|
|
|
'handler' => $handler, |
|
55
|
|
|
]; |
|
56
|
|
|
|
|
57
|
|
|
$this->setExpectedException( |
|
58
|
|
|
'GuzzleHttp\Exception\BadResponseException' |
|
59
|
|
|
); |
|
60
|
|
|
|
|
61
|
|
|
$pusher = new MetricPusher($options, (new BufferedIO()), (new SdkClient( |
|
62
|
|
|
[ |
|
63
|
|
|
'username' => null, |
|
64
|
|
|
'password' => null, |
|
65
|
|
|
'base_uri' => '/', |
|
66
|
|
|
'handler' => $handler, |
|
67
|
|
|
] |
|
68
|
|
|
))); |
|
69
|
|
|
$pusher->push((new Result($this->createUrlInfo(), 200, 0.200, null, null))); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
private function createUrlInfo($validator = true) |
|
|
|
|
|
|
73
|
|
|
{ |
|
74
|
|
|
return new UrlInfo( |
|
75
|
|
|
'google', |
|
76
|
|
|
'https://www.google.fr', |
|
77
|
|
|
'GET', |
|
78
|
|
|
[], |
|
79
|
|
|
1, |
|
80
|
|
|
200, |
|
81
|
|
|
(new Validator([])), |
|
82
|
|
|
null, |
|
83
|
|
|
null |
|
84
|
|
|
); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.