summaryrefslogtreecommitdiff
path: root/StatsdDataFactoryTest.php
blob: 144f629c3bbf8a5a44af15279299e9f200f98907 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php

namespace Liuggio\StatsdClient\Factory;

use Liuggio\StatsdClient\Factory\StatsdDataFactory;

class StatsDataFactoryTest extends \PHPUnit_Framework_TestCase
{
    private $statsDataFactory;

    public function setUp()
    {
        $this->statsDataFactory = new StatsdDataFactory('\Liuggio\StatsdClient\Entity\StatsdData');
    }

    public function testProduceStatsdData()
    {
        $key = 'key';
        $value='val';

        $obj = $this->statsDataFactory->produceStatsdData($key, $value);
        $this->assertEquals($key, $obj->getKey());
        $this->assertEquals($value, $obj->getValue());
    }

    public function testTiming()
    {
        $key = 'key';
        $value = microtime();
        $valueFloat = (string) floatval($value);

        $obj = $this->statsDataFactory->timing($key, $value);
        $this->assertEquals($key, $obj->getKey());
        $this->assertContains($valueFloat, $obj->getValue());
        $this->assertContains('ms', $obj->getMetric());
    }

    public function testProduceStatsdDataDecrement()
    {
        $key = 'key';
        $value = -1;
        $stringValue = intval($value);

        $obj = $this->statsDataFactory->produceStatsdData($key, $value);
        $this->assertEquals($key, $obj->getKey());
        $this->assertEquals($stringValue, $obj->getValue());
        $this->assertEquals('c', $obj->getMetric());
    }

    public function testGauge()
    {
        $key = 'key';
        $value = 1000;
        $stringValue = (string) intval($value);

        $obj = $this->statsDataFactory->gauge($key, $value);
        $this->assertEquals($key, $obj->getKey());
        $this->assertEquals($stringValue, $obj->getValue());
        $this->assertEquals('g', $obj->getMetric());
    }

    public function testDecrement()
    {
        $key = 'key';
        $value = -1;
        $stringValue = intval($value);

        $obj = $this->statsDataFactory->decrement($key);
        $this->assertEquals($key, $obj->getKey());
        $this->assertEquals($stringValue, $obj->getValue());
        $this->assertEquals('c', $obj->getMetric());
    }

    public function testcreateStatsdDataIncrement()
    {
        $key = 'key';
        $value = 1;
        $stringValue = intval($value);

        $obj = $this->statsDataFactory->increment($key);
        $this->assertEquals($key, $obj->getKey());
        $this->assertEquals($stringValue, $obj->getValue());
        $this->assertEquals('c', $obj->getMetric());
    }

    public function testCreateStatsdDataUpdateCount()
    {
        $key = 'key';
        $value = 10;
        $stringValue = intval($value);

        $obj = $this->statsDataFactory->updateCount($key, 10);
        $this->assertEquals($key, $obj->getKey());
        $this->assertEquals($stringValue, $obj->getValue());
        $this->assertEquals('c', $obj->getMetric());
    }
}