MetricsCollectorPassTest::testValidCollector()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 9.392
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
use Flagbit\Bundle\MetricsBundle\DependencyInjection\Compiler\MetricsCollectorPass;
4
use Flagbit\Bundle\MetricsBundle\Provider\ProviderInvoker;
5
use PHPUnit\Framework\TestCase;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Definition;
8
use Symfony\Component\DependencyInjection\Reference;
9
10
class MetricsCollectorPassTest extends TestCase
11
{
12
    public function testMetricsProviderNoCollectorThrowsException()
13
    {
14
        $services = [
15
            'my_metric_collector' => [0 => []]
16
        ];
17
18
        $container = $this->createMock(ContainerBuilder::class);
19
        $container->expects($this->once())
20
            ->method('findTaggedServiceIds')
21
            ->with('metrics.provider')
22
            ->willReturn($services);
23
24
        $this->expectException('InvalidArgumentException');
25
26
        $metricsCollectorPass = new MetricsCollectorPass();
27
        $metricsCollectorPass->process($container);
0 ignored issues
show
Documentation introduced by
$container is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...ction\ContainerBuilder>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
28
    }
29
30
    public function testValidCollector()
31
    {
32
        $services = [
33
            'my_metric_collector' => [0 => ['collector' => 'librato']]
34
        ];
35
36
        $definition = $this->createMock(Definition::class);
37
        $container = $this->createMock(ContainerBuilder::class);
38
39
        $container->expects($this->atLeastOnce())
40
            ->method('hasDefinition')
41
            ->willReturn(true);
42
43
        $container->expects($this->once())
44
            ->method('getDefinition')
45
            ->with(ProviderInvoker::class)
46
            ->willReturn($definition);
47
48
        $container->expects($this->atLeastOnce())
49
            ->method('findTaggedServiceIds')
50
            ->with('metrics.provider')
51
            ->willReturn($services);
52
53
        $definition->expects($this->once())
54
            ->method('addMethodCall')
55
            ->with('addMetricsProvider', [
56
                new Reference('my_metric_collector'),
57
                [new Reference('beberlei_metrics.collector.librato')]
58
            ]);
59
60
        $metricsCollectorPass = new MetricsCollectorPass();
61
        $metricsCollectorPass->process($container);
0 ignored issues
show
Documentation introduced by
$container is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...ction\ContainerBuilder>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
62
    }
63
}
64