1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of graze/dog-statsd |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @license https://github.com/graze/dog-statsd/blob/master/LICENSE.md |
12
|
|
|
* @link https://github.com/graze/dog-statsd |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Graze\DogStatsD\Test\Unit; |
16
|
|
|
|
17
|
|
|
use Graze\DogStatsD\Client; |
18
|
|
|
use Graze\DogStatsD\Test\TestCase; |
19
|
|
|
|
20
|
|
|
class EventTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
public function testSimpleEvent() |
23
|
|
|
{ |
24
|
|
|
$this->client->event('some_title', 'textAndThings'); |
25
|
|
|
$this->assertEquals('_e{10,13}:some_title|textAndThings', $this->client->getLastMessage()); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testEventMetadata() |
29
|
|
|
{ |
30
|
|
|
$this->client->event( |
31
|
|
|
'some_title', |
32
|
|
|
'textAndThings', |
33
|
|
|
[ |
34
|
|
|
'time' => 12345678, |
35
|
|
|
'hostname' => 'some.host', |
36
|
|
|
'key' => 'someKey', |
37
|
|
|
'priority' => Client::PRIORITY_LOW, |
38
|
|
|
'source' => 'space', |
39
|
|
|
'alert' => Client::ALERT_INFO, |
40
|
|
|
] |
41
|
|
|
); |
42
|
|
|
$this->assertEquals( |
43
|
|
|
'_e{10,13}:some_title|textAndThings|d:12345678|h:some.host|k:someKey|p:low|s:space|t:info', |
44
|
|
|
$this->client->getLastMessage() |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testEventTags() |
49
|
|
|
{ |
50
|
|
|
$this->client->event( |
51
|
|
|
'some_title', |
52
|
|
|
'textAndThings', |
53
|
|
|
[ |
54
|
|
|
'time' => 12345678, |
55
|
|
|
], |
56
|
|
|
['tag'] |
57
|
|
|
); |
58
|
|
|
$this->assertEquals( |
59
|
|
|
'_e{10,13}:some_title|textAndThings|d:12345678|#tag', |
60
|
|
|
$this->client->getLastMessage() |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testEventTextReplacesNewLines() |
65
|
|
|
{ |
66
|
|
|
$this->client->event('some_title', "LongText\rAnd\nStuff"); |
67
|
|
|
$this->assertEquals("_e{10,18}:some_title|LongTextAnd\\nStuff", $this->client->getLastMessage()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testCoreStatsDImplementation() |
71
|
|
|
{ |
72
|
|
|
$this->client->configure([ |
73
|
|
|
'host' => '127.0.0.1', |
74
|
|
|
'port' => 8125, |
75
|
|
|
'dataDog' => false, |
76
|
|
|
]); |
77
|
|
|
$this->client->event('some_title', 'textAndThings'); |
78
|
|
|
$this->assertEquals('', $this->client->getLastMessage()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function testLongMessage() |
82
|
|
|
{ |
83
|
|
|
$this->client->event( |
84
|
|
|
'long_message', |
85
|
|
|
str_repeat('x', 10000) |
86
|
|
|
); |
87
|
|
|
|
88
|
|
|
$this->assertEquals('_e{12,10000}:long_message|' . str_repeat('x', 10000), $this->client->getLastMessage()); |
89
|
|
|
$this->assertTrue($this->client->wasSuccessful()); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|