-
Notifications
You must be signed in to change notification settings - Fork 1
/
MetricsCounterTest.php
39 lines (33 loc) · 1.15 KB
/
MetricsCounterTest.php
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
<?php
declare(strict_types=1);
namespace Per3evere\Preq\Test;
use PHPUnit\Framework\TestCase;
use Per3evere\Preq\Contract\StateStorage as StateStorageContract;
use Per3evere\Preq\MetricsCounter;
class MetricsCounterTest extends TestCase
{
private $counter;
private $cacheTestDouble;
/**
* @before
*/
public function setupCounter()
{
$commandKey = 'Per3evere.Preq.TestCommand';
$this->cacheTestDouble = $cache = $this->createStub(StateStorageContract::class);
$rollingStatisticalWindowInMilliseconds = 10000;
$rollingStatisticalWindowBuckets = 10;
$this->counter = new MetricsCounter($commandKey, $cache, $rollingStatisticalWindowInMilliseconds, $rollingStatisticalWindowBuckets);
}
public function testAdd()
{
$this->cacheTestDouble->expects($this->once())->method('incrementBucket');
$this->counter->add('type');
}
public function testGet()
{
$this->cacheTestDouble->method('getBucket')->willReturn(1);
$this->cacheTestDouble->expects($this->exactly(10))->method('getBucket');
$this->assertEquals(10, $this->counter->get('type'));
}
}