|
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); |
|
|
|
|
|
|
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); |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
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: