Skip to content
This repository was archived by the owner on Dec 22, 2025. It is now read-only.

Commit f119f5c

Browse files
committed
Covered Timer with tests
1 parent 522bfb3 commit f119f5c

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

tests/Timer/LogTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace HelloFresh\Stats\Timer;
4+
5+
6+
use PHPUnit\Framework\TestCase;
7+
8+
class LogTest extends TestCase
9+
{
10+
public function testFinish()
11+
{
12+
/** @var \PHPUnit_Framework_MockObject_MockObject|\Psr\Log\LoggerInterface $logger */
13+
$logger = $this->getMockBuilder('\Psr\Log\LoggerInterface')->getMock();
14+
15+
$logger->expects($this->once())
16+
->method('debug')
17+
->willReturnCallback(function ($message, array $context) {
18+
$this->assertEquals('Stats timer finished', $message);
19+
$this->assertArrayHasKey('elapsed', $context);
20+
});
21+
22+
$timer = new Log($logger);
23+
$timer->start();
24+
$timer->finish('hello.world');
25+
}
26+
}

tests/Timer/MemoryTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace HelloFresh\Stats\Timer;
4+
5+
6+
use PHPUnit\Framework\TestCase;
7+
8+
class MemoryTest extends TestCase
9+
{
10+
public function testFinish()
11+
{
12+
$timer = new Memory();
13+
$timer->start();
14+
$timer->finish('hello.world');
15+
16+
$this->assertEquals('hello.world', $timer->getMetric());
17+
$this->assertEquals('hello.world', $timer->getMetric());
18+
19+
$metric = $timer->elapsed();
20+
$this->assertInstanceOf(Metric::class, $metric);
21+
$this->assertEquals('hello.world', $metric->getMetric());
22+
}
23+
}

tests/Timer/StatsDTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace HelloFresh\Stats\Timer;
4+
5+
6+
use PHPUnit\Framework\TestCase;
7+
8+
class StatsDTest extends TestCase
9+
{
10+
public function testFinish()
11+
{
12+
/** @var \PHPUnit_Framework_MockObject_MockObject|\League\StatsD\Client $statsd */
13+
$statsd = $this->getMockBuilder('\League\StatsD\Client')->getMock();
14+
15+
$statsd->expects($this->once())
16+
->method('timing')
17+
->willReturnCallback(function ($metric, $time) {
18+
$this->assertEquals('hello.world', $metric);
19+
});
20+
21+
$timer = new StatsD($statsd);
22+
$timer->start();
23+
$timer->finish('hello.world');
24+
}
25+
}

0 commit comments

Comments
 (0)