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\Test\TestCase; |
17
|
|
|
|
18
|
|
|
class CounterTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
public function testIncrement() |
21
|
|
|
{ |
22
|
|
|
$this->client->increment('test_metric', 1); |
23
|
|
|
$this->assertEquals('test_metric:1|c', $this->client->getLastMessage()); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testIncrementDelta() |
27
|
|
|
{ |
28
|
|
|
$this->client->increment('test_metric', 2); |
29
|
|
|
$this->assertEquals('test_metric:2|c', $this->client->getLastMessage()); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testIncrementSample() |
33
|
|
|
{ |
34
|
|
|
while ($this->client->getLastMessage() === '') { |
35
|
|
|
$this->client->increment('test_metric', 1, 0.75); |
36
|
|
|
} |
37
|
|
|
$this->assertEquals('test_metric:1|c|@0.75', $this->client->getLastMessage()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testIncrementSampleFailure() |
41
|
|
|
{ |
42
|
|
|
$this->client->increment('test_metric', 1, 0); |
43
|
|
|
$this->assertEquals('', $this->client->getLastMessage()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testDecrement() |
47
|
|
|
{ |
48
|
|
|
$this->client->decrement('test_metric'); |
49
|
|
|
$this->assertEquals('test_metric:-1|c', $this->client->getLastMessage()); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testDecrementDelta() |
53
|
|
|
{ |
54
|
|
|
$this->client->decrement('test_metric', 3); |
55
|
|
|
$this->assertEquals('test_metric:-3|c', $this->client->getLastMessage()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testIncrementTags() |
59
|
|
|
{ |
60
|
|
|
$this->client->increment('test_metric', 1, 1, ['tag']); |
61
|
|
|
$this->assertEquals('test_metric:1|c|#tag', $this->client->getLastMessage()); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|