Completed
Push — master ( f1e1ae...7e3292 )
by Denis
10:20 queued 02:02
created

RendererTest::testRenderResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 15
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Tests\Artprima\PrometheusMetricsBundle\Metrics;
6
7
use Artprima\PrometheusMetricsBundle\Metrics\AppMetrics;
8
use Artprima\PrometheusMetricsBundle\Metrics\Renderer;
9
use PHPUnit\Framework\TestCase;
10
use Prometheus\CollectorRegistry;
11
use Prometheus\MetricFamilySamples;
12
13
class RendererTest extends TestCase
14
{
15
    public function testRender()
16
    {
17
        $collectionRegistry = $this->createMock(CollectorRegistry::class);
18
        $collectionRegistry->expects(self::once())->method('getMetricFamilySamples')->willReturn([new MetricFamilySamples([
19
            'name' => 'name',
20
            'type' => 'type',
21
            'help' => 'help',
22
            'labelNames' => [],
23
            'samples' => [],
24
        ])]);
25
        $metrics = new AppMetrics();
26
        $metrics->init('test_ns', $collectionRegistry);
27
        $renderer = new Renderer($collectionRegistry);
28
        $response = $renderer->render();
29
        $this->assertEquals("# HELP name help\n# TYPE name type\n", $response);
30
    }
31
32
    public function testRenderResponse()
33
    {
34
        $collectionRegistry = $this->createMock(CollectorRegistry::class);
35
        $collectionRegistry->expects(self::once())->method('getMetricFamilySamples')->willReturn([new MetricFamilySamples([
36
            'name' => 'name',
37
            'type' => 'type',
38
            'help' => 'help',
39
            'labelNames' => [],
40
            'samples' => [],
41
        ])]);
42
        $metrics = new AppMetrics();
43
        $metrics->init('test_ns', $collectionRegistry);
44
        $renderer = new Renderer($collectionRegistry);
45
        $response = $renderer->renderResponse();
46
        $this->assertContains("# HELP name help\n# TYPE name type\n", $response->getContent());
47
    }
48
}
49