This repository was archived by the owner on Dec 22, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +74
-0
lines changed
Expand file tree Collapse file tree 3 files changed +74
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments