|
| 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 DistributionTest extends TestCase |
| 19 | +{ |
| 20 | + public function testDistribution() |
| 21 | + { |
| 22 | + $this->client->distribution('test_metric', 10); |
| 23 | + $this->assertEquals('test_metric:10|d', $this->client->getLastMessage()); |
| 24 | + |
| 25 | + $this->client->distribution('test_metric', 1.2); |
| 26 | + $this->assertEquals('test_metric:1.2|d', $this->client->getLastMessage()); |
| 27 | + } |
| 28 | + |
| 29 | + public function testDistributionSample() |
| 30 | + { |
| 31 | + while ($this->client->getLastMessage() === '') { |
| 32 | + $this->client->distribution('test_metric', 5, 0.75); |
| 33 | + } |
| 34 | + $this->assertEquals('test_metric:5|d|@0.75', $this->client->getLastMessage()); |
| 35 | + } |
| 36 | + |
| 37 | + public function testDistributionSampleFailure() |
| 38 | + { |
| 39 | + $this->client->distribution('test_metric', 5, 0); |
| 40 | + $this->assertEquals('', $this->client->getLastMessage()); |
| 41 | + } |
| 42 | + |
| 43 | + public function testDistributionTags() |
| 44 | + { |
| 45 | + $this->client->distribution('test_metric', 10, 1.0, []); |
| 46 | + $this->assertEquals('test_metric:10|d', $this->client->getLastMessage()); |
| 47 | + |
| 48 | + $this->client->distribution('test_metric', 10, 1.0, ['tag1']); |
| 49 | + $this->assertEquals('test_metric:10|d|#tag1', $this->client->getLastMessage()); |
| 50 | + |
| 51 | + $this->client->distribution('test_metric', 10, 1.0, ['tag1', 'tag2']); |
| 52 | + $this->assertEquals('test_metric:10|d|#tag1,tag2', $this->client->getLastMessage()); |
| 53 | + |
| 54 | + $this->client->distribution('test_metric', 10, 1.0, ['tag1', 'tag1']); |
| 55 | + $this->assertEquals('test_metric:10|d|#tag1,tag1', $this->client->getLastMessage()); |
| 56 | + } |
| 57 | +} |
0 commit comments