1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Beberlei\Metrics\Collector\Collector; |
4
|
|
|
use Flagbit\Bundle\MetricsBundle\Collector\CollectorCollection; |
5
|
|
|
use Flagbit\Bundle\MetricsBundle\Collector\Factory\CollectorCollectionFactory; |
6
|
|
|
use Flagbit\Bundle\MetricsBundle\Provider\ProviderInterface; |
7
|
|
|
use Flagbit\Bundle\MetricsBundle\Provider\ProviderInvoker; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
|
10
|
|
|
class ProviderInvokerTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject |
14
|
|
|
*/ |
15
|
|
|
private $factory; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var ProviderInvoker |
19
|
|
|
*/ |
20
|
|
|
private $metricsProvider; |
21
|
|
|
|
22
|
|
|
protected function setUp() |
23
|
|
|
{ |
24
|
|
|
$this->factory = $this->createMock(CollectorCollectionFactory::class); |
25
|
|
|
$this->metricsProvider = new ProviderInvoker($this->factory); |
|
|
|
|
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testAddMetricsProvider() |
29
|
|
|
{ |
30
|
|
|
$collector = $this->createMock(Collector::class); |
31
|
|
|
$provider = $this->createMock(ProviderInterface::class); |
32
|
|
|
|
33
|
|
|
$this->getCollectorCollection($collector); |
34
|
|
|
|
35
|
|
|
$this->metricsProvider->addMetricsProvider($provider, [$collector]); |
|
|
|
|
36
|
|
|
} |
37
|
|
|
|
38
|
|
View Code Duplication |
public function testCollectMetrics() |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
$collector = $this->createMock(Collector::class); |
41
|
|
|
$provider = $this->createMock(ProviderInterface::class); |
42
|
|
|
$collectorCollection = $this->getCollectorCollection($collector); |
43
|
|
|
|
44
|
|
|
$provider |
45
|
|
|
->expects($this->once()) |
46
|
|
|
->method('collectMetrics') |
47
|
|
|
->with($collectorCollection); |
48
|
|
|
|
49
|
|
|
$this->metricsProvider->addMetricsProvider($provider, [$collector]); |
|
|
|
|
50
|
|
|
$this->metricsProvider->collectMetrics(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
View Code Duplication |
public function testOnTerminate() |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
$collector = $this->createMock(Collector::class); |
56
|
|
|
$provider = $this->createMock(ProviderInterface::class); |
57
|
|
|
$collectorCollection = $this->getCollectorCollection($collector); |
58
|
|
|
|
59
|
|
|
$provider |
60
|
|
|
->expects($this->once()) |
61
|
|
|
->method('collectMetrics') |
62
|
|
|
->with($collectorCollection); |
63
|
|
|
|
64
|
|
|
$this->metricsProvider->addMetricsProvider($provider, [$collector]); |
|
|
|
|
65
|
|
|
$this->metricsProvider->collectMetrics(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
private function getCollectorCollection($collector) |
69
|
|
|
{ |
70
|
|
|
$collectorCollection = $this->createMock(CollectorCollection::class); |
71
|
|
|
|
72
|
|
|
$this->factory |
73
|
|
|
->expects($this->once()) |
74
|
|
|
->method('create') |
75
|
|
|
->willReturn($collectorCollection); |
76
|
|
|
|
77
|
|
|
$collectorCollection |
78
|
|
|
->expects($this->once()) |
79
|
|
|
->method('addCollector') |
80
|
|
|
->with($collector); |
81
|
|
|
|
82
|
|
|
return $collectorCollection; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
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: