Completed
Push — master ( 70b352...622f18 )
by Harry
02:46
created

EventTest::testLongMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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